Private WithEvents olkInbox As Outlook.Items
Private Sub Application_MAPILogonComplete()
Set olkInbox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Application_Quit()
Set olkInbox = Nothing
End Sub
Private Sub olkInbox_ItemAdd(ByVal Item As Object)
Dim olkHeader As Outlook.RemoteItem, _
olkProp As Outlook.PropertyAccessor, _
olkContacts As Outlook.Items, _
olkContact As Outlook.ContactItem, _
olkCmdBar As Office.CommandBar, _
olkCmdBarPop As Office.CommandBarPopup, _
olkCmdBarBtn As Office.CommandBarButton, _
olkExplorer As Outlook.Explorer, _
strAddress As String
If Item.Class = olRemote Then
Set olkContacts = Session.GetDefaultFolder(olFolderContacts).Items
Set olkHeader = Item
Set olkProp = olkHeader.PropertyAccessor
strAddress = olkProp.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1F001E")
On Error Resume Next
Set olkContact = olkContacts.Find("[Email1Address] = '" & strAddress & "' OR [Email2Address] = '" & strAddress & "' OR [Email3Address] = '" & strAddress & "'")
If TypeName(olkContact) = "ContactItem" Then
olkHeader.MarkForDownload = olMarkedForDownload
olkHeader.Save
Set olkExplorer = Application.ActiveExplorer
Set olkCmdBar = olkExplorer.CommandBars("Retrieve Mail From")
'Replace 8 on the following line with the position number of the selection you want to make'
Set olkCmdBarPop = olkCmdBar.Controls.Item(8)
Set olkCmdBarBtn = olkCmdBarPop.Controls(3)
olkCmdBarBtn.Execute
End If
On Error GoTo 0
End If
Set olkHeader = Nothing
Set olkProp = Nothing
Set olkContacts = Nothing
Set olkContact = Nothing
Set olkCmdBar = Nothing
Set olkCmdBarPop = Nothing
Set olkCmdBarBtn = Nothing
Set olkExplorer = Nothing
End Sub
|