With the following code, I could get the attachments transfer to HardDrive.
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Att As Attachment
Dim FileName As String
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
For Each Item In Inbox.Items
For Each Att In Item.Attachments
FileName = "C:\myfolder\" & Att.FileName
Att.SaveAsFile FileName
Next Att
Next Item
However, I want to adrress the Subject name should be "xxxxxxxx" then save
the attachment. I added the condition into the following code.
I run the code, it's been compile error 91 [Object variable or With Block
variable not set]
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Att As Attachment
Dim FileName As String
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Dim Msg As Outlook.MailItem
Set Msg = Item
For Each Item In Inbox.Items
If (Msg.Subject = "Statement") Then
For Each Att In Item.Attachments
FileName = "C:\myfolder\" & Att.FileName
Att.SaveAsFile FileName
Next Att
End If
Next Item
Please give me suggestions.
March
March said:
Dear All,
I would like to know how to automate saving the attachment while I open
email. I have no idea where to start. I plan to write VBA. I do resecrh on
VBA and try to work on SaveAsFile Method, it doesn't work. Please give me
suggestions.
Thanks,
March