设置 outlook.attachment = 邮件项目附件



我正在尝试编写一个将附件保存到目录的脚本。 当我运行它时,我收到一条错误消息"类型不匹配",并且突出显示了Set olAtt = olMi.Attachments行。 有人可以建议吗?

Sub SaveAttachments()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olMi As Outlook.MailItem
Dim olAtt As Outlook.Attachment
Dim MyPath As String
Dim i As Long
Dim j As Long
Dim filesavename As String
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set MoveToFldr = Fldr.Folders("Survey")
MyPath = "C:Userstemp"

For i = (Fldr.Items.Count - 150) To Fldr.Items.Count 
    Set olMi = Fldr.Items(i)
    If InStr(1, olMi.Subject, "Survey") > 0 Then
        j = olMi.Attachments.Count
        Set olAtt = olMi.Attachments
        filesavename = MyPath & olAtt.Filename
        olAtt.SaveAsFile filesavename
        olMi.Save
        olMi.Move MoveToFldr
    End If
Next i
Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub

olAtt被声明为Outlook.Attachment(单数)。

olMi.Attachments是附件的集合。

相关内容

  • 没有找到相关文章

最新更新