使用VBScript自动保存Outlook中的附件

时间:2013-06-21 11:29:23

标签: vbscript outlook

我有以下代码:

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中收件箱中的电子邮件中的附件,任何有关使其正常工作的帮助将非常感激:)

由于

0 个答案:

没有答案