i can't get this to work for the life of me. i'm trying to automate saving an attachment when specific emails come in. I haven't even added the boolean language yet.... sheesh. any guidance with this would definitely be helpful.
Option Explicit
Private WithEvents olInboxItems As Items
Private Sub Application_NewMail()
Dim objNS As Outlook.NameSpace
Dim X As Integer
Set objNS = GetNamespace("MAPI")
Set olInboxItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
Dim NS As NameSpace
Dim MYINBOX As mapifolder
Dim MYITEM As MailItem
Set NS = GetNamespace("MAPI")
Set MYINBOX = NS.GetDefaultFolder(olFolderInbox)
If TypeOf Item Is MailItem Then
Set MYITEM = Item
If MYITEM.Attachments.Count = 1 Then
MYITEM.Attachments.Item(1).SaveAsFile "C:\Users\jvaughn\Desktop\Test\" & MYITEM.Attachments.Item(1).DisplayName
End If
End If
Set NS = Nothing
Set MYINBOX = Nothing
End Sub
Bookmarks