【发布时间】:2022-01-18 04:14:54
【问题描述】:
我正在尝试在 VBA Outlook 中运行此 VBA 代码,我的主要目标是将任何新的即将发送的邮件作为文件保存到选定的文件夹中。但是,当我运行此脚本时,它什么也不做,它不保存任何新的即将发送的电子邮件。也许你可以看看这个,并帮助我?非常感谢。
Private Sub Application_Startup()
Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub olItems_ItemAdd(ByVal Item As Object)
Dim NewMail As Outlook.MailItem
Dim Atts As Attachments
Dim Att As Attachment
Dim strPath As String
Dim strName As String
If Item.Class = olMail Then
Set NewMail = Item
End If
Set Atts = Item.Attachments
If Atts.Count > 0 Then
For Each Att In Atts
If InStr(LCase(Att.FileName), “”) > 0 Then
strPath = “selected path”
strName = NewMail.Subject & ” ” & Chr(45) & ” ” & Att.FileName
Att.SaveAsFile strPath & strName
End If
Next
End If
End Sub
【问题讨论】:
-
检查我对另一个问题的回答,我在其中展示了如何设置监听器。这与您的工作流程有关。 stackoverflow.com/questions/51637693/…
-
olItems声明在哪里?它必须是任何 Sub...之外的 Global...