Results 1 to 13 of 13

Thread: Outlook AddinInstance_onconnection

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Question Outlook AddinInstance_onconnection

    1. When I create outlook object [set objoutlook=createobject("Outlook.Application")] will the addinInstance_OnConnection() will be executed. If so, is it immediately after its created or its asynchoronous.
    2. And also addinInstance_Onconnection calls the InitHandler procedure only when either Explorers.count or Inspectors.count is not equal to zero. When outlook opens how the count will be zero.

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

    Re: Outlook AddinInstance_onconnection

    The OnConnection event should not require you to create your own Outlook instance. You can set a public outlook application object = to the outlook application instance that is passed in to the procedure. This is the proper way.
    VB Code:
    1. Option Explicit
    2.  
    3. Public moApp As Outlook.Application
    4.  
    5. Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
    6.     set moApp = Application
    7.    '...
    8. 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

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: Outlook AddinInstance_onconnection

    actually i am creating my own outlook object from a procedure in a class module. In that case will the addinInstance_OnConnection () be executed??

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: Outlook AddinInstance_onconnection

    VB Code:
    1. Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
    2.    ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
    3.    ByVal AddInInst As Object, custom() As Variant)
    4.     On Error Resume Next
    5.     'Evaluate ConnectMode
    6.    
    7.     Select Case ConnectMode
    8.         Case ext_cm_Startup
    9.         Case ext_cm_AfterStartup
    10.         Case ext_cm_CommandLine
    11.         Case ext_cm_Startup
    12.     End Select
    13.     'Don't call InitHandler if Explorers.Count = 0 and Inspectors.Count = 0
    14.     If Application.Explorers.Count = 0 And Application.Inspectors.Count = 0 Then
    15.         Exit Sub
    16.     End If
    17.    
    18.    'AddInInst represents COMAddIn object
    19.     'Create and Initialize a base class
    20.    
    21.     gBaseClass.InitHandler Application, AddInInst.ProgId
    22.     'DebugWrite "IDT2 OnConnection"
    23. End Sub
    24.  
    25.  
    26. Method where i create another outlook object is below.
    27.  
    28. Public Sub Display()
    29. Dim blnNew As Boolean
    30. Dim myFolder As MAPIFolder
    31. Dim myNameSpc As NameSpace
    32.  
    33.    
    34. On Error Resume Next
    35. If golApp Is Nothing Then  "Open outlook if it is not already open
    36.     blnEnableEmail = GetSetting("shsmith", "EnableMail", "EMAIL", True)
    37.     If blnEnableEmail Then
    38.         Set olOut = CreateObject("Outlook.Application")
    39.         Set myNameSpc = olOut.GetNamespace("MAPI")
    40.         Set myFolder = myNameSpc.GetDefaultFolder(olFolderInbox)
    41.         myfolder.Display
    42.         'Set objOutlook = olOut
    43.         'Set golApp = olOut
    44.         'golApp.ActiveExplorer.Activate
    45.         Set olOut = Nothing
    46.         Set myNameSpc = Nothing
    47.         blnOutCreated = True
    48.     End If
    49. Else
    50.     blnOutCreated = True
    51. End If
    52.     If blnOutCreated Then
    53.         Set objCB = golApp.ActiveExplorer.CommandBars("SHSMITH") ' Test if the Items toolbar already exists
    54.         If Err Then
    55.             blnNew = True
    56.         ' Create a new items toolbar.
    57.             Set objCB = golApp.ActiveExplorer.CommandBars.Add _
    58.                 (Name:="SHSMITH", Position:=msoBarRight, Temporary:=False)
    59.        
    60.             Set objCBPop = objCB.Controls.Add(Type:=msoControlPopup)
    61.             With objCBPop
    62.                 .Caption = "SHSMITH"
    63.                 .ToolTipText = "Attach To Correspondence"
    64.             End With
    65.             Set objCBButton = CreateAddInCommandBarButton(gstrProgID, objCBPop, _
    66.             "Attach Email To Correspondence", "SHSMITH", "Attach To Email Correspondence", 1757, False, msoButtonCaption)
    67.         End If
    68.         blnOutCreated = False
    69.     End If
    70.     'Display toolbar if new
    71.     If blnNew Then objCB.Visible = True
    72. end sub
    73.  
    74. INITHANDLER LOOKS LIKE THIS.
    75.  
    76. Friend Sub InitHandler(olApp As Outlook.Application, strProgID As String)
    77.     On Error Resume Next
    78.      'Declared WithEvents
    79.     'Instantiate a public module-level Outlook application variable
    80.     Set golApp = olApp
    81.     Set objOutlook = olApp
    82.     gstrProgID = strProgID
    83.     'CBOutlookItems objOutlook.ActiveExplorer.CurrentFolder
    84.     End Sub
    Last edited by RobDog888; Aug 3rd, 2005 at 10:50 AM. Reason: Added vbcode tags for easier reading

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

    Re: Outlook AddinInstance_onconnection

    Ok, your line here: gBaseClass.InitHandler Application, AddInInst.ProgId is passing the Application object to your inithandler where your setting your public app var golApp = to it. Thats fine except that an addin usually depends on Outlook starting up on its own. Not too sure if an addin can start Outlook seeing how the addin will not be connected nor have any Application object to pass into the OnConnection event. Sounds like your logic may need improving but what does your addin do anyways?
    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

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: Outlook AddinInstance_onconnection

    my addin will create a command bar on the outlook.When the button is clicked after selceting an item from a folder, the item object will be passed to VB app which will save the item in the VB application.
    In the same way,when a mail is sent the dll will pick it up from the sent items folder and pass the object again to VB app which will save the item in the application.

    The thing is, When the VB app is run if outlook is not open then a new outlook has to be opened else if outlook is already open, then only the button needs to be added to the existing outlook instance.

    currently we have a custom built dll that is working fine, but unfortunately the contract developer took the source with him and we have only the dll. We are trying to code it again.

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: Outlook AddinInstance_onconnection

    And also currently the display method opens new outlook but in addininstance_onconnection procedure since Explorers and Inspectors counts are zero the button is not displayed.
    And also display method opens new outlook even though an instance is already opened by the user.

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

    Re: Outlook AddinInstance_onconnection

    Ok, got a little better picture of whats going on. You VB app will shell Outlook if its not running. Then it will only create a toolbar button if it was already 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

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: Outlook AddinInstance_onconnection

    VB app will not Shell outlook ...COM DLL will shell outlook if its not running. COM DLL will create the toolbar button if it is already running.

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

    Re: Outlook AddinInstance_onconnection

    This COM dll is the Outlook Add-In, correct? If so it needs Outlook to be running first so it can load th 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

  11. #11

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: Outlook AddinInstance_onconnection

    so do you mean to say that from the outlook com addin we will not be able to shell outlook??.

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

    Re: Outlook AddinInstance_onconnection

    No, I'm not saying that but it would be a new separate instance of Outlook and would not be a Trusted instance and would incur all the security popups from Outlook.
    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

  13. #13

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: Outlook AddinInstance_onconnection

    i am able to create a new instance if there isnt one already but the problem is it is not executing the inithandler procedure as app.explorers.count =0 and this condition is checked in addininstance_onconnection, where the inithandler is also called.

    because of this...i am not able to create buttons.

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