Results 1 to 10 of 10

Thread: outlook events

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Question outlook events

    HI,
    I have created a outlook com dll and VB app. An event raised (SEND)in the outlook com dll is not fired in the vb app. the event will be raised whenever an item is added to the sentitems folder. The dll raises another event(ATTACH) whenever a command button is clicked(button is created by the dll). The attach event is fired in the vb app but not the Send event. How to solve this??

    adhi

  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 events

    Are you attaching to the passed in Outlook.Application object in the OnConnection 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 events

    here is the code. I am not calling it in the onconnetion sub.
    VB Code:
    1. '******************************************************************************
    2. 'Outlook COM Add-In project template
    3. 'This sample code provided by Micro Eye, Inc.
    4. 'http://www.microeye.com
    5. 'This code is unsupported, and cannot be posted or reproduced without
    6. 'explicit permission of Micro Eye, Inc.
    7. 'IDTExtensibility2 is the interface that COM Add-ins must implement.
    8. 'The project references the following object libraries:
    9. 'Add additional object libraries as required for your COM Add-in
    10. 'References:
    11. 'Microsoft Add-In Designer
    12. 'Microsoft Outlook 9.0 Object Library
    13. 'Microsoft Office 9.0 Object Library
    14. 'Class: OutAddIn
    15. 'Instancing: MultiUse
    16. 'Public Events:
    17. 'Public Functions:
    18. 'Public Properties:
    19. '******************************************************************************
    20. Option Explicit
    21. 'Object variables for Event procedures
    22. Private WithEvents objOutlook As Outlook.Application
    23. Private WithEvents olSentItems As Items
    24. Private WithEvents objExpl As Outlook.Explorer
    25. Private WithEvents objCBButton As Office.CommandBarButton
    26. Private objCB As Office.CommandBar
    27. Private objCBPop As Office.CommandBarPopup
    28.  
    29. '******************************************************************************
    30. Public Event Send(MailItem As Object)
    31. Public Event Attach(Selection As Outlook.Selection)
    32. Private blnEnableSend As Boolean
    33. Private blnEnableEmail As Boolean
    34. Public Sub Display()
    35. Dim blnNew As Boolean
    36.  
    37. ' Test if the Items toolbar already exists
    38. On Error Resume Next
    39. LogNTEvent 1, vbLogEventTypeInformation, "Display method"
    40. Set objCB = Application.ActiveExplorer.CommandBars("SHSMITH")
    41. If Err Then
    42.         blnNew = True
    43.         ' Create a new items toolbar.
    44.         Set objCB = Application.ActiveExplorer.CommandBars.Add(Name:="SHSMITH", Position:=msoBarRight, Temporary:=False)
    45.         Set objCBPop = objCB.Controls.Add(Type:=msoControlPopup)
    46.         With objCBPop
    47.             .Caption = "SHSMITH"
    48.             .ToolTipText = "Attach To Correspondence"
    49.         End With
    50.         Set objCBButton = CreateAddInCommandBarButton(gstrProgID, objCBPop, _
    51.             "Attach Email To Correspondence", "SHSMITH", "Attach To Email Correspondence", 1757, False, msoButtonCaption)
    52. End If
    53.        
    54. 'Display toolbar if new
    55. If blnNew Then objCB.Visible = True
    56.  
    57. End Sub
    58. Friend Sub InitHandler(olApp As Outlook.Application, strProgID As String)
    59.     On Error Resume Next
    60.     LogNTEvent 1, vbLogEventTypeInformation, "InitHandler"
    61.     'Declared WithEvents
    62.     'Instantiate a public module-level Outlook application variable and Outlook variable WithEvents
    63.     Set objOutlook = olApp
    64.     Set golApp = olApp
    65.     Set objExpl = objOutlook.ActiveExplorer
    66.     gstrProgID = strProgID
    67.     LogNTEvent 1, vbLogEventTypeInformation, "InitHandler and golapp is " & golApp & "objOutlook is " & objOutlook & "ProgID is " & gstrProgID
    68.     'CBOutlookItems objOutlook.ActiveExplorer.CurrentFolder
    69. End Sub
    70. Friend Sub UnInitHandler()
    71.     If Not objCB Is Nothing Then
    72.         objCB.Delete
    73.     End If
    74.     Set objCB = Nothing
    75.     Set objCBPop = Nothing
    76.     Set objCBButton = Nothing
    77.     Set golApp = Nothing
    78.     Set objOutlook = Nothing
    79. End Sub
    80. Private Sub Class_Initialize()
    81.  'Dim myFolder As MAPIFolder
    82.  'Dim myNameSpc As NameSpace
    83.  
    84.   '  blnEnableEmail = GetSetting("shsmith", "EnableMail", "EMAIL", True)
    85.    ' If golApp Is Nothing Then
    86.     '    LogNTEvent 1, vbLogEventTypeInformation, "Outlook is not open"
    87.      '   If blnEnableEmail Then
    88.       '     LogNTEvent 1, vbLogEventTypeInformation, "Outlook is not open SHSMITH has to open outlook"
    89.        '    Set olOut = CreateObject("Outlook.Application")
    90.         '   Set myNameSpc = olOut.GetNamespace("MAPI")
    91.          '  Set myFolder = myNameSpc.GetDefaultFolder(olFolderInbox)
    92.           ' myFolder.Display
    93.            'Set golApp = olOut
    94.            'Set objOutlook = olOut
    95.            'Set myNameSpc = Nothing
    96.            'Set olOut = Nothing
    97.         'End If
    98.    'End If
    99.    
    100. End Sub
    101. Private Sub Class_Terminate()
    102.     If Not objCB Is Nothing Then
    103.         objCB.Delete
    104.     End If
    105.     Set objCB = Nothing
    106.     If Not golApp Is Nothing Then
    107.         golApp.Quit
    108.     End If
    109.     Set golApp = Nothing
    110.     Set objOutlook = Nothing
    111. End Sub
    112. Private Sub objCBButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
    113.  
    114.     RaiseEvent Attach(Application.ActiveExplorer.Selection)
    115.  
    116. End Sub
    117. Private Sub objExpl_Close()
    118.     If objExpl Is Nothing Then
    119.     Else
    120.         Set objExpl = Nothing
    121.     End If
    122.     UnInitHandler
    123. End Sub
    124. [B]Private Sub objOutlook_Startup()
    125.     Dim objNS As NameSpace
    126.     LogNTEvent 1, vbLogEventTypeInformation, "objOutlook object is starting up to listen to Sent items "
    127.    
    128.     Set objNS = objOutlook.GetNamespace("MAPI")
    129.     Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
    130.     'Set objNS = Nothing
    131.    
    132. End Sub
    133.  Private Sub olSentItems_ItemAdd(ByVal Item As Object)
    134.     Dim obItem As Object
    135.    
    136.     blnEnableSend = GetSetting("shsmith", "EnableSend", "EMAILSEND", True)
    137.     If blnEnableSend Then
    138.         LogNTEvent 1, vbLogEventTypeInformation, "Send is enabled and I am going to raise the event " & objOutlook
    139.         Set obItem = Item
    140.         RaiseEvent Send(obItem)
    141.     End If
    142.    
    143. End Sub[/B]
    144. Public Property Let MenuCaption(ByVal vNewValue As String)
    145. '     objCB.Name = vNewValue
    146. End Property
    147. Public Property Let ButtonCaption(ByVal vNewValue As String)
    148.  '  objCBButton.Caption = vNewValue
    149. End Property
    150. Public Property Let ToolTipText(ByVal vNewValue As String)
    151.   '  objCBButton.ToolTipText = vNewValue
    152. End Property
    153. Public Property Get Send_Enabled() As Variant
    154.    ' Send_Enabled = blnSEnabled
    155. End Property
    156. Public Property Let Send_Enabled(ByVal vNewValue As Variant)
    157.     '  blnSEnabled = vNewValue
    158. End Property

    The event Send is defined in the VB app like this (below one is the test app)

    Private Sub objOutlook_Send(MailItem As Object)
    MsgBox "The Mail has been sent and it is in Sent items folder"
    End Sub

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

    Re: outlook events

    Well to be a compatible Add-In you need to use the "Implements IDTExtensibility" so you can create and use the OnConnection procedure and others. This is where the Application object is passied in to your program. I dont see where the olApp is being passed in from?
    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
    Member
    Join Date
    Jul 2005
    Posts
    40

    Question Re: outlook events

    olApp is passed from the OnConnection sub. here is the code.
    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.     Select Case ConnectMode
    7.         Case ext_cm_Startup
    8.         Case ext_cm_AfterStartup
    9.         Case ext_cm_CommandLine
    10.         Case ext_cm_Startup
    11.     End Select
    12.     If Application.Explorers.Count = 0 And Application.Inspectors.Count = 0 Then 'Outlook launched with UI
    13.         Exit Sub
    14.     End If
    15.     gBaseClass.InitHandler Application, AddInInst.ProgId
    16.     'DebugWrite "IDT2 OnConnection"
    17. End Sub

    u know actuall the olSentItems_ItemAdd is executed but the RaiseEvent Send(obitem) does not fire the objoutlook_Send(mailitem as object) sub in the VB app.

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

    Re: outlook events

    But your raising and event passing a passed in object?
    VB Code:
    1. Private Sub olSentItems_ItemAdd(ByVal Item As Object)
    2. ...
    3. Set obItem = Item
    4. ...
    5. RaiseEvent Send(obItem)
    Is this code being executed?
    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
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: outlook events

    the procedure olSentItems_ItemAdd is executed. When it executes the statement RaiseEvent Send the Send procedure defined in the VB app is not getting executed, instead its just goes to next statement in olSentItems_ItemAdd procedure.

    adhi

  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 events

    Ok this may shed some light on it.
    For example, if a form has a Click event, you can't fire its Click event using RaiseEvent. If you declare a Click event in the form module, it shadows the form’s own Click event. You can still invoke the form’s Click event using normal syntax for calling the event, but not using the RaiseEvent statement.
    Wheres you Send procedure? I assume your trying to raise an event that is not declared in the class.
    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 events

    the Send Procedure is in the VB app.
    VB Code:
    1. Option Explicit
    2. Private WithEvents objOutlook As NewOutlookAddIn
    3. Private Sub Command1_Click()
    4. Set objOutlook = Nothing
    5.  
    6. Unload Me
    7. End Sub
    8. Private Sub Form_Load()
    9. Set objOutlook = New NewOutlookAddIn
    10.  
    11. 'objOutlook.Send_Enabled = True
    12. objOutlook.Display
    13. End Sub
    14. Private Sub objOutlook_Attach(Selection As Outlook.Selection)
    15.     MsgBox "mail has been attached to the app"
    16. End Sub
    17. Private Sub objOutlook_Send(MailItem As Object)
    18.    MsgBox "The Mail has been sent and it is in Sent items folder"
    19. End Sub

    I have delcared the event in the dll class at the top as
    VB Code:
    1. Public Event Send(MailItem As Object)

  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 events

    An Event and a WithEvent are different things. Try ...
    VB Code:
    1. Public WithEvents Send(MailItem As Object)
    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

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