
Setting Inbox to process mail items
Use this code :
Note : Item.sendername will display only the sendername...and not the email
to Greg Busby.
Regards
Natarajan
Option Explicit
Dim OutlookApp As Outlook.Application
Dim MynameSpace As NameSpace
Dim FolderList As Outlook.MAPIFolder
Public WithEvents myOlInboxItems As Outlook.Items
Public Sub SaveFiles(Mail As MailItem)
' Do some processing
End Sub
Sub ExtractAttachments()
Set OutlookApp = GetObject(, "Outlook.Application")
Set MynameSpace = OutlookApp.GetNamespace("MAPI")
Set FolderList = MynameSpace.GetDefaultFolder(olFolderInbox)
Set myOlInboxItems = FolderList.Items
End Sub
Private Sub Application_Startup()
Call ExtractAttachments
End Sub
Private Sub Application_Quit()
Set myOlInboxItems = Nothing
End Sub
Private Sub myolInboxItems_ItemAdd(ByVal Item As Object)
MsgBox Item.SenderName
If Item.SenderName = "Greg Busby" And Item.Attachments.Count > 0 Then
Item.Move (FolderList.Folders.Item("Test"))
Call SaveFiles(FolderList)
End If
End Sub
Quote:
> I'm a newbie with what must be a simplistic question. How
> do I set olInboxItems to the Inbox folder collection? I'm
> trying to run my SaveFiles method everytime an email
> arrives in the Inbox. However, I'm getting a compile
> error that it can't find an object when I try to set the
> olInboxItems in the ExtractAttachements procedure. I'm
> really lost here. Thanks for any assistance/guidance.
> Option Explicit
> >> Private WithEvents olInboxItems As MailItem
> >> Dim OutlookApp As Outlook.Application
> >> Dim MynameSpace As NameSpace
> >> Dim FolderList As Outlook.MAPIFolder
> >> Dim strAddressNumber As String
> >> Public Sub SaveFiles(Mail as MailItem)
> >> ' Do some processing
> >> End Sub
> >> Sub ExtractAttachments()
> >> Dim flist As Outlook.MAPIFolder
> >> Set OutlookApp = GetObject(, "Outlook.Application")
> >> Set MynameSpace = OutlookApp.GetNamespace("MAPI")
> >> Set FolderList = MynameSpace.GetDefaultFolder
> >> (olFolderInbox)
> >> Set FolderList = FolderList.Folders.Item("Inbox")
> >> Call SaveFiles(FolderList)
> >> End Sub
> >> Private Sub Application_Startup()
> >> Call ExtractAttachments
> >> End Sub
> >> Private Sub Application_Quit()
> >> Set olInboxItems = Nothing
> >> End Sub
> >> Private Sub olInboxItems_ItemAdd(ByVal Item As MailItem)
> >> Item.Attachments.Count > 0 Then
> >> Item.Move (FolderList.Folders.Item("Test"))
> >> Call SaveFiles(FolderList)
> >> End If
> >> End Sub