Hi im new to using outlook but i do have some programing experience, what i want to do is that whenever i close an email message i want this macro to run, but i dont know how to do this, and if that is possible, is there a way to make this macro run only on the first time i read the mail?
please help
I'm trying to use WithEvents to get the closing mailItem event to trigger my macro, i found this code off the internet for getting the mailitem but i cant seem to get it to work, help plzzz
Dim WithEvents vInspectors As Outlook.Inspectors
Dim WithEvents vExplorers As Outlook.Explorers
Dim WithEvents vExplorer As Outlook.Explorer
Dim WithEvents vMailItem As Outlook.MailItem
'I use the following code to get the vMailItem variable set:
Private Sub Class_Initialize()
Set vInspectors = Application.Inspectors
Set vExplorers = Application.Explorers
If Not ActiveExplorer Is Nothing Then
Set vExplorer = ActiveExplorer
If TypeName(vExplorer.Selection.Item(1)) = "MailItem" Then
Set vMailItem = vExplorer.Selection.Item(1)
End If
End If
End Sub
Private Sub Class_Terminate()
Set vInspectors = Nothing
Set vExplorer = Nothing
Set vExplorers = Nothing
Set vMailItem = Nothing
End Sub
Private Sub vExplorer_SelectionChange()
If vExplorer.Selection.Count = 1 And TypeName(vExplorer.Selection.Item(1)) = _
"MailItem" Then Set vMailItem = vExplorer.Selection.Item(1)
End Sub
Private Sub vExplorers_NewExplorer(ByVal Explorer As Explorer)
Set vExplorer = Explorer
If TypeName(vExplorer.Selection.Item(1)) = "MailItem" Then
Set vMailItem = vExplorer.Selection.Item(1)
End If
End Sub
Private Sub vInspectors_NewInspector(ByVal Inspector As Inspector)
If TypeName(Inspector.CurrentItem) = "MailItem" Then
Set vMailItem = Inspector.CurrentItem
End If
End Sub
'and then after this i guess i use
Private Sub vMailItem_Close()
' my codes for the macro
end sub
Is that right??