2

我有以下代码:

Option Explicit 
Dim WithEvents TargetFolderItems As Items 
 'set the string constant for the path to save attachments
Const FILE_PATH As String = "H:\Attachment" 

Private Sub Application_Startup() 
    Dim ns As Outlook.NameSpace 
    Set ns = Application.GetNamespace("MAPI") 
    Set TargetFolderItems = ns.Folders.Item( _ 
    "Inbox").Folders.Item("BS CDGL").Items 
End Sub 

Sub TargetFolderItems_ItemAdd(ByVal Item As Object) 
    Dim olAtt As Attachment 
    Dim i As Integer 

    If Item.Attachments.Count > 0 Then 
        For i = 1 To Item.Attachments.Count 
            Set olAtt = Item.Attachments(i) 
             'save the attachment
            olAtt.SaveAsFile FILE_PATH & olAtt.FileName 
        Next 
    End If 

    Set olAtt = Nothing 
End Sub 

Private Sub Application_Quit() 
    Dim ns As Outlook.NameSpace 
    Set TargetFolderItems = Nothing 
    Set ns = Nothing 
End Sub

它在第 2 行第 16 行字符“TargetFolderItems”部分引发错误,代码是自动保存 Outlook 收件箱中电子邮件的附件,非常感谢任何帮助实现此工作:)

谢谢

4

0 回答 0