我在我的 oulook VBE 中从一个 VBA 社区复制了以下代码,并根据我的需要对其进行了修改。我可以使用 F5 和 F8 运行它。现在,每当我在文件夹 1 中收到电子邮件时,我都想运行这个宏。我尝试设置规则,但看不到“运行脚本”选择框中列出的宏。我已经检查过了
- 宏安全设置正确
- 宏在一个模块中而不是在一个类中
你能告诉我设置中出了什么问题吗?
Public Sub SaveAttachments()
Dim myOlapp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim yourFolder As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem
Dim myAttachment As Outlook.Attachment
Dim I As Long
Set myOlapp = CreateObject("Outlook.Application")
Set myNameSpace = myOlapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set yourFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myFolder = myFolder.Folders("folder1")
Set yourFolder = yourFolder.Folders("folder2")
For Each myItem In myFolder.Items
If myItem.Attachments.Count <> 0 Then
For Each myAttachment In myItem.Attachments
I = I + 1
myAttachment.SaveAsFile "C:\arthur\test.csv"
Next
End If
myItem.Move yourFolder
Next
End Sub