Results 1 to 24 of 24

Thread: .Net Addin for Outlook

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    .Net Addin for Outlook

    Hi,

    I am trying to write an AddIn for Vb.Net which will display the 'Select Names' dialog (the one that appears when you click on To when creating a blank email).

    I have currently created an Addin to create a specific type of mail message, but I could not get the dialog box to appear. To resolve this I had to create my own version of the dialog box, but this is very slow when populating.

    My only other thought is to create a message using a form created in Outlook, and try basing it on that.

    Any suggestions would be great!

    Many thanks,

    -Graham

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    Welcome to the Forums.

    I had written code to do this exact thing over at another forum just a day or two ago.

    What version of .NET are you running?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Hi,

    I am using .Net 2003, but have access to 2005 (what ever version you have will be great!).

    Many thanks,

    -Graham

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    Ok, but you can not make an Add-In for Outlook with VS.NET. You need VSTO 2005 w/Outlook Beat 1 Add-In in order to create one in .NET. I havent installed it since its Beta but you can write one in VB 6.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Hi,

    It is possible to write an addin in vs 2003 but it does effectively use COM to communicate, which makes me think I cannot make the dialog box appear.

    Is it possible to use a newly created Outlook form and subclass it to obtain the events (i.e. when a person presses a key in a textbox?). As I can't seem to pick these up with Outlook 2003.

    Sadly upgrading to the new version of Outlook isn't possible for me.

    -Graham

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    A COM Add-In for Outlook would be in the form of a .dll file but there is no template or other functionality to create an Add-In for Outlook. The Visual Studio Tools for Office 2005 contains support for the other extra Add-In for Outlook but its VSTO Outlook Beta 1 stll.

    You can just use automation in VB.NET to interact with Outlook but it wont be an actual Add-In.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    You can create an addin in Vb 2003 using a template.

    Create a new project, select project type as 'Other Projects' and then select 'Extensibility Projects' and then Shared Add-in.

    You then get a wizard which you can select Outlook from.

    -Graham

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    Yes, you are correct. I cant believe that I missed that feature of .NET I have read on Microsofts site that an Outlook Add-In was unsupported until 2005's VSTO.

    Thanks for the info Let the programming begin.

    Ok, give me some time as I have written some VB 6 code to display the "Select Names" dialog earlier this week. All I have to do is convert it to .NET and test.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    Are you adding a reference to Outlook or using Late Binding? What version of Outlook are you running?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    I am using Outlook 2003, and it Vb imports the Microsoft.Office.Core namespace, although most of the objects it defines by default are late bound (so defined as objects via vb.net).

    If you have already written a vb6 addin, can you send me the code from that so that I can save you some work?

    Many thanks for your help.

    -Graham

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    But shouldnt you be setting a reference to Outlook and using the .Interop class?
    I havent written a VB6 AddIn but just a VB6 code snippet that does it.


    VB Code:
    1. Option Explicit
    2. 'Add a reference to MS Outlook xx.0 Object Library
    3. 'Add a reference to MS Office xx.0 Object Library
    4. 'Note: Menu Items are spelling and language specific
    5. '      Written on Outlook 2003.
    6. Private Sub Command1_Click()
    7.     Dim oApp As Outlook.Application
    8.     Dim oCB As Office.CommandBar
    9.     Dim oCBTools As Office.CommandBarPopup
    10.     Dim oCBSelect As Office.CommandBarButton
    11.     Dim oInsp As Outlook.Inspector
    12.     Dim oCont As Outlook.MailItem
    13.    
    14.     Set oApp = New Outlook.Application
    15.     oApp.GetNamespace("MAPI").Logon "", "", False, True
    16.    
    17.     Set oCont = oApp.CreateItem(olMailItem)
    18.     Set oInsp = oCont.GetInspector
    19.     oInsp.Display vbModeless
    20.     oInsp.WindowState = olNormalWindow
    21.     oInsp.Left = -10000 'Set the Inspector off screen.
    22.    
    23.     Set oCB = oInsp.CommandBars("Menu Bar")
    24.     Set oCBTools = oCB.Controls("&Tools")
    25.     Set oCBSelect = oCBTools.Controls("Address &Book...")
    26.     oCBSelect.Execute
    27.     MsgBox oCont.To 'Just for display example. Set into a variable or ?
    28.     oInsp.Left = 250 'Set to 250 or ? to return it to viewable location
    29.     oCont.Close olDiscard
    30.     Set oCont = Nothing
    31.     Set oCBSelect = Nothing
    32.     Set oCBTools = Nothing
    33.     Set oCB = Nothing
    34.     Set oApp = Nothing
    35. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Thank you, I've got the code working in .Net (I haven't tried it in my add in yet).

    I have never used the Inspector object, and I hadn't even thought of using the command to select it from the menu item. I'd been digging around the object model but getting nowhere.

    Thank you very much.

    -Graham
    P.S. Is it possible to amend the address book so that instead of showing the business phone number first, it uses the mobile number field.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    Can you post your .NET version of it?

    How so do you mean? To preselect the combo at the top right corner of the dialog or the number being used in the contact item?

    The Inspector is only the container that displays a email message, appointmentitem, contactitem, etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    This is my very quick and dirty version of the code, I'll tart it up and make look pretty on Monday (when I am back at work).

    Anyway here goes (sorry, don't know the code to format this and make it nice and readable):

    VB Code:
    1. Imports Microsoft.Office.Core
    2.  
    3. Public Class Form1
    4.     Inherits System.Windows.Forms.Form
    5.  
    6.  
    7.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    8.         Dim oInsp As Outlook.Inspector
    9.         Dim oMail As Outlook.MailItem
    10.  
    11.         mOutlook = New Outlook.Application
    12.         oMail = mOutlook.CreateItem(Outlook.OlItemType.olMailItem)
    13.         oInsp = oMail.GetInspector
    14.  
    15.         oInsp.Display(0)
    16.         oInsp.WindowState = Outlook.OlWindowState.olNormalWindow
    17.         oInsp.Left = -10000
    18.  
    19.         Dim oCB As CommandBar
    20.         Dim oCBTools As CommandBarPopup
    21.         Dim oCBSelect As CommandBarButton
    22.  
    23.         oCB = oInsp.CommandBars("Menu Bar")
    24.         oCBTools = oCB.Controls("&Tools")
    25.         oCBSelect = oCBTools.Controls("Address &Book...")
    26.         oCBSelect.Execute()
    27.  
    28.         MsgBox(oMail.To)
    29.  
    30.     End Sub
    31. End Class


    Sorry, bad explanation before...

    In the dialog it shows the business phone number as the second column in the listview. I would like to change that to show the mobile phone number that is stored for the person. Which can be accessed by double clicking the persons name from the To list (to bring up their properties), select the 'Phone/Notes' tab, the mobile number is displayed there.
    I think this is installed with exchange 2003, as the mobile numbers are stored in active directory under each user.

    I doubt this is possible, but anyhelp would be great.

    Many thanks for all of your help.

    -Graham
    Last edited by RobDog888; Jan 13th, 2006 at 12:00 PM. Reason: Added [vbcode] tags

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    I dont have Exchange running but Im unsure on how to set the preference.

    Oh, I thought you were going to post more of the app.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Quote Originally Posted by RobDog888
    [color=navy]I dont have Exchange running but Im unsure on how to set the preference.
    Installing ex 2003 adds some parts to active directory, which is what I want to display in the dialog. Is it possible to amend that dialog at all?

    Quote Originally Posted by RobDog888
    Oh, I thought you were going to post more of the app.
    Ah, sorry.
    I didn't have a chance to implement it before I left work today.

    When I am back at work next week, I'll make it look a bit nicer than it is currently post that.

    Once again, many thanks for all of your help!

    -Graham

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    I think if you ned to highly customize the dialog, then you would want to create your own form and duplicate what you want. You can load it with the same information, not too hard.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Quote Originally Posted by RobDog888
    I think if you ned to highly customize the dialog, then you would want to create your own form and duplicate what you want. You can load it with the same information, not too hard.
    Thats is what I originally was doing for the form, it was just taking a long time to populate the list view.

    I'll add the ameded code for the addin later today.

    -Graham

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    What if you prepopulated it upon the start of Outlook or loading of your addin? Then its like a .Show and.Hide thing and not reloading each time?

    NP, I'll be back later this morning and I'll check out the thread.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Quote Originally Posted by RobDog888
    What if you prepopulated it upon the start of Outlook or loading of your addin? Then its like a .Show and.Hide thing and not reloading each time?

    NP, I'll be back later this morning and I'll check out the thread.
    You can do that, but due to a bug (not sure if it is in .Net or Outlook) the event when outlook is closed does not fire if there are open references open (so you can't use it to clean up as you would normally).

    -Graham

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    Oh, thats correct. It retains your apps instance and doesnt close it. This is supposed to be fixed in the VSTO Outlook Add-In.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Sorry for the delay, but I have been allocated to a different project now, and it doesn't look like I will be working on this again for a few weeks.

    Anyway, the code as I have it at the moment (if it is of anyuse to anyone):

    Connect.Vb (This class is mostly written by VB when the addin is created, but I have added some stuff to make an icon appear on the Outlook toolbar).

    Please forgive any dodgy code, as it is very much work in progress (and it isn't very nice in some places!)
    Connect.Vb
    VB Code:
    1. Imports Microsoft.Office.Core
    2. imports Extensibility
    3. Imports System.Runtime.InteropServices
    4.  
    5.  
    6. #Region " Read me for Add-in installation and setup information. "
    7. ' When run, the Add-in wizard prepared the registry for the Add-in.
    8. ' At a later time, if the Add-in becomes unavailable for reasons such as:
    9. '   1) You moved this project to a computer other than which is was originally created on.
    10. '   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
    11. '   3) Registry corruption.
    12. ' you will need to re-register the Add-in by building the SMSOutlookSetup project
    13. ' by right clicking the project in the Solution Explorer, then choosing install.
    14. #End Region
    15.  
    16. <GuidAttribute("EF730A67-8CCE-4F1F-9EFA-F5880F767DD0"), ProgIdAttribute("SMSOutlook.Connect")> _
    17. Public Class Connect
    18.    
    19.     Implements Extensibility.IDTExtensibility2
    20.    
    21.     Public applicationObject As Object
    22.     Public addInInstance As Object
    23.     Public WithEvents cmdbarMyAddin As CommandBarButton
    24.     Private frmMyForm As New frmMine
    25.  
    26.     Public ReadOnly Property OutlookObject()
    27.         Get
    28.             applicationObject = OutlookObject
    29.         End Get
    30.     End Property
    31.  
    32.     Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
    33.         On Error Resume Next
    34.         ' Notify the user you are shutting down, and delete the button.
    35.         frmMyForm.Dispose()
    36.         frmMyForm = Nothing
    37.         cmdbarMyAddin.Delete()
    38.         cmdbarMyAddin= Nothing
    39.     End Sub
    40.  
    41.     Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
    42.     End Sub
    43.  
    44.     ' This event fires (I think) when Outlook has finished loading.  Most of the code was auto generated by the
    45.     'AddIn (On error resume next), how nice.
    46.     ' Basically it will add a button called MyAddin to the Outlook main window.
    47.     Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
    48.         Dim oCommandBars As CommandBars
    49.         Dim oStandardBar As CommandBar
    50.  
    51.         On Error Resume Next
    52.         ' Set up a custom button on the "Standard" command bar.
    53.         oCommandBars = applicationObject.CommandBars
    54.         If oCommandBars Is Nothing Then
    55.             ' Outlook has the CommandBars collection on the Explorer object.
    56.             oCommandBars = applicationObject.ActiveExplorer.CommandBars
    57.         End If
    58.  
    59.         oStandardBar = oCommandBars.Item("Standard")
    60.  
    61.         ' In case the button was not deleted, use the exiting one.
    62.         cmdbarMyAddin = oStandardBar.Controls.Item("My Addin")
    63.         If cmdbarMyAddin Is Nothing Then
    64.  
    65.             cmdbarMyAddin = oStandardBar.Controls.Add(1)
    66.             With cmdbarMyAddin
    67.                 .Caption = "My Addin"
    68.                 '.Style = MsoButtonStyle.msoButtonIcon
    69.                 .Style = MsoButtonStyle.msoButtonCaption
    70.  
    71.                 ' The following items are optional, but recommended.
    72.                 ' The Tag property lets you quickly find the control
    73.                 ' and helps MSO keep track of it when more than
    74.                 ' one application window is visible. The property is required
    75.                 ' by some Office applications and should be provided.
    76.  
    77.                 .Tag = "My Addin"
    78.  
    79.                 ' The OnAction property is optional but recommended.
    80.                 ' It should be set to the ProgID of the add-in, so that if
    81.                 ' the add-in is not loaded when a user clicks the button,
    82.                 ' MSO loads the add-in automatically and then raises
    83.                 ' the Click event for the add-in to handle.
    84.  
    85.                 .OnAction = "!<MyCOMAddin.Connect>"
    86.  
    87.                 .Visible = True
    88.             End With
    89.         End If
    90.  
    91.         ' Display a simple message to show which application you started in.
    92.  
    93.         oStandardBar = Nothing
    94.         oCommandBars = Nothing
    95.     End Sub
    96.  
    97.     Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
    98.         On Error Resume Next
    99.  
    100.         If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
    101.            Call OnBeginShutdown(custom)
    102.  
    103.         applicationObject = Nothing
    104.     End Sub
    105.  
    106.     Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
    107.         applicationObject = application
    108.         addInInstance = addInInst
    109.  
    110.         ' If you aren't in startup, manually call OnStartupComplete.
    111.         If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
    112.            Call OnStartupComplete(custom)
    113.  
    114.     End Sub
    115.  
    116.     Private Sub cmdbarMyAddin_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles cmdbarMyAddin.Click
    117.         Try
    118.             Dim frmMyForm As New frmMine
    119.             frmMyForm = New frmSms
    120.             frmMyForm.Outlookref = CType(applicationObject, Outlook.Application)
    121.             frmMyForm.Show()
    122.         Catch ex As Exception
    123.             MsgBox("An error has occured with the AddIn." & vbCrLf & "Error details : " & Err.Description)
    124.         End Try
    125.     End Sub
    126.  
    127. End Class

    Then in the form (which I have made to look similar to a normal email).
    Clicking on a button on that I will have to use the code you gave me above to create a new EMail message and then bring up the Address book.

    I have had to strip out some peices of the code (so I hope it compiles) just my work doesn't like it if I post their name and code.
    Saying that, I am happy to help as much as I can and I hope that is of some use.

    Many thanks Master Yoda for all of your help!

    -Graham
    Last edited by GRussell31; Jan 18th, 2006 at 12:26 PM.

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: .Net Addin for Outlook

    Thanks! What I did notice is that your using the .Core instead of the .Interop. Interop is better if your running Ourlook 2002 or 2003.
    VB Code:
    1. Imports Microsoft.Office.Interop
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  24. #24

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    12

    Re: .Net Addin for Outlook

    Quote Originally Posted by RobDog888
    Thanks! What I did notice is that your using the .Core instead of the .Interop. Interop is better if your running Ourlook 2002 or 2003.
    VB Code:
    1. Imports Microsoft.Office.Interop
    That'll be the lovely auto generated code!

    Good spot, I just hope I can work on it soon before I forget all this again!

    Thanks,

    -Graham

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width