我是从观看的youtube视频中编写此代码的,但是尽管遵循了指示,但是当我尝试运行宏时,我的第二行代码却始终显示为错误?
-
Option Explicit
'early binding
Sub outlook_email_save()
Dim olook As Outlook.Application
Set olook = New Outlook.Application
Dim omail As Outlook.MailItem
Set omail = olook.CreateItem(olMailItem)
Dim ospace As Outlook.Namespace
Set ospace = olook.GetNamespace("MAPI")
Dim myfold As Outlook.Folder
Set myfold = ospace.GetDefaultFolder(olFolderInbox).Folders(Range("D2").Value)
Dim atmt As Attachment
For Each omail In myfol.Items
If omail.Subject Like "*" & Range("A2:A519").Value & "*" Then
For Each atmt In omail.Attachments
If atmt.Filename Like "*" & Range("B2").Value & "*" Then
atmt.SaveAsFile Range("C2").Value & atmt.Filename
Else
'do nothing
End If
Next
Else
'do nothing
End If
Next
End Sub
目标: 从Outlook电子邮件中以主题行“ Invoice.pdf”下载名为“ INVOICE CSF57796,INVOICE CSF56381,INVOICE CSF55242 ...”的所有附件,并将其存储在本地桌面文件夹中。