|
-
Aug 18th, 2005, 01:07 PM
#1
Thread Starter
Member
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
-
Aug 19th, 2005, 12:12 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 19th, 2005, 07:48 AM
#3
Thread Starter
Member
Re: outlook events
here is the code. I am not calling it in the onconnetion sub.
VB Code:
'******************************************************************************
'Outlook COM Add-In project template
'This sample code provided by Micro Eye, Inc.
'http://www.microeye.com
'This code is unsupported, and cannot be posted or reproduced without
'explicit permission of Micro Eye, Inc.
'IDTExtensibility2 is the interface that COM Add-ins must implement.
'The project references the following object libraries:
'Add additional object libraries as required for your COM Add-in
'References:
'Microsoft Add-In Designer
'Microsoft Outlook 9.0 Object Library
'Microsoft Office 9.0 Object Library
'Class: OutAddIn
'Instancing: MultiUse
'Public Events:
'Public Functions:
'Public Properties:
'******************************************************************************
Option Explicit
'Object variables for Event procedures
Private WithEvents objOutlook As Outlook.Application
Private WithEvents olSentItems As Items
Private WithEvents objExpl As Outlook.Explorer
Private WithEvents objCBButton As Office.CommandBarButton
Private objCB As Office.CommandBar
Private objCBPop As Office.CommandBarPopup
'******************************************************************************
Public Event Send(MailItem As Object)
Public Event Attach(Selection As Outlook.Selection)
Private blnEnableSend As Boolean
Private blnEnableEmail As Boolean
Public Sub Display()
Dim blnNew As Boolean
' Test if the Items toolbar already exists
On Error Resume Next
LogNTEvent 1, vbLogEventTypeInformation, "Display method"
Set objCB = Application.ActiveExplorer.CommandBars("SHSMITH")
If Err Then
blnNew = True
' Create a new items toolbar.
Set objCB = Application.ActiveExplorer.CommandBars.Add(Name:="SHSMITH", Position:=msoBarRight, Temporary:=False)
Set objCBPop = objCB.Controls.Add(Type:=msoControlPopup)
With objCBPop
.Caption = "SHSMITH"
.ToolTipText = "Attach To Correspondence"
End With
Set objCBButton = CreateAddInCommandBarButton(gstrProgID, objCBPop, _
"Attach Email To Correspondence", "SHSMITH", "Attach To Email Correspondence", 1757, False, msoButtonCaption)
End If
'Display toolbar if new
If blnNew Then objCB.Visible = True
End Sub
Friend Sub InitHandler(olApp As Outlook.Application, strProgID As String)
On Error Resume Next
LogNTEvent 1, vbLogEventTypeInformation, "InitHandler"
'Declared WithEvents
'Instantiate a public module-level Outlook application variable and Outlook variable WithEvents
Set objOutlook = olApp
Set golApp = olApp
Set objExpl = objOutlook.ActiveExplorer
gstrProgID = strProgID
LogNTEvent 1, vbLogEventTypeInformation, "InitHandler and golapp is " & golApp & "objOutlook is " & objOutlook & "ProgID is " & gstrProgID
'CBOutlookItems objOutlook.ActiveExplorer.CurrentFolder
End Sub
Friend Sub UnInitHandler()
If Not objCB Is Nothing Then
objCB.Delete
End If
Set objCB = Nothing
Set objCBPop = Nothing
Set objCBButton = Nothing
Set golApp = Nothing
Set objOutlook = Nothing
End Sub
Private Sub Class_Initialize()
'Dim myFolder As MAPIFolder
'Dim myNameSpc As NameSpace
' blnEnableEmail = GetSetting("shsmith", "EnableMail", "EMAIL", True)
' If golApp Is Nothing Then
' LogNTEvent 1, vbLogEventTypeInformation, "Outlook is not open"
' If blnEnableEmail Then
' LogNTEvent 1, vbLogEventTypeInformation, "Outlook is not open SHSMITH has to open outlook"
' Set olOut = CreateObject("Outlook.Application")
' Set myNameSpc = olOut.GetNamespace("MAPI")
' Set myFolder = myNameSpc.GetDefaultFolder(olFolderInbox)
' myFolder.Display
'Set golApp = olOut
'Set objOutlook = olOut
'Set myNameSpc = Nothing
'Set olOut = Nothing
'End If
'End If
End Sub
Private Sub Class_Terminate()
If Not objCB Is Nothing Then
objCB.Delete
End If
Set objCB = Nothing
If Not golApp Is Nothing Then
golApp.Quit
End If
Set golApp = Nothing
Set objOutlook = Nothing
End Sub
Private Sub objCBButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
RaiseEvent Attach(Application.ActiveExplorer.Selection)
End Sub
Private Sub objExpl_Close()
If objExpl Is Nothing Then
Else
Set objExpl = Nothing
End If
UnInitHandler
End Sub
[B]Private Sub objOutlook_Startup()
Dim objNS As NameSpace
LogNTEvent 1, vbLogEventTypeInformation, "objOutlook object is starting up to listen to Sent items "
Set objNS = objOutlook.GetNamespace("MAPI")
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
'Set objNS = Nothing
End Sub
Private Sub olSentItems_ItemAdd(ByVal Item As Object)
Dim obItem As Object
blnEnableSend = GetSetting("shsmith", "EnableSend", "EMAILSEND", True)
If blnEnableSend Then
LogNTEvent 1, vbLogEventTypeInformation, "Send is enabled and I am going to raise the event " & objOutlook
Set obItem = Item
RaiseEvent Send(obItem)
End If
End Sub[/B]
Public Property Let MenuCaption(ByVal vNewValue As String)
' objCB.Name = vNewValue
End Property
Public Property Let ButtonCaption(ByVal vNewValue As String)
' objCBButton.Caption = vNewValue
End Property
Public Property Let ToolTipText(ByVal vNewValue As String)
' objCBButton.ToolTipText = vNewValue
End Property
Public Property Get Send_Enabled() As Variant
' Send_Enabled = blnSEnabled
End Property
Public Property Let Send_Enabled(ByVal vNewValue As Variant)
' blnSEnabled = vNewValue
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
-
Aug 19th, 2005, 08:00 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 19th, 2005, 08:30 AM
#5
Thread Starter
Member
Re: outlook events
olApp is passed from the OnConnection sub. here is the code.
VB Code:
Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
On Error Resume Next
'Evaluate ConnectMode
Select Case ConnectMode
Case ext_cm_Startup
Case ext_cm_AfterStartup
Case ext_cm_CommandLine
Case ext_cm_Startup
End Select
If Application.Explorers.Count = 0 And Application.Inspectors.Count = 0 Then 'Outlook launched with UI
Exit Sub
End If
gBaseClass.InitHandler Application, AddInInst.ProgId
'DebugWrite "IDT2 OnConnection"
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.
-
Aug 19th, 2005, 08:35 AM
#6
Re: outlook events
But your raising and event passing a passed in object?
VB Code:
Private Sub olSentItems_ItemAdd(ByVal Item As Object)
...
Set obItem = Item
...
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 19th, 2005, 08:41 AM
#7
Thread Starter
Member
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
-
Aug 19th, 2005, 09:12 AM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 19th, 2005, 09:17 AM
#9
Thread Starter
Member
Re: outlook events
the Send Procedure is in the VB app.
VB Code:
Option Explicit
Private WithEvents objOutlook As NewOutlookAddIn
Private Sub Command1_Click()
Set objOutlook = Nothing
Unload Me
End Sub
Private Sub Form_Load()
Set objOutlook = New NewOutlookAddIn
'objOutlook.Send_Enabled = True
objOutlook.Display
End Sub
Private Sub objOutlook_Attach(Selection As Outlook.Selection)
MsgBox "mail has been attached to the app"
End Sub
Private Sub objOutlook_Send(MailItem As Object)
MsgBox "The Mail has been sent and it is in Sent items folder"
End Sub
I have delcared the event in the dll class at the top as
VB Code:
Public Event Send(MailItem As Object)
-
Aug 19th, 2005, 01:21 PM
#10
Re: outlook events
An Event and a WithEvent are different things. Try ...
VB Code:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|