91对象变量或块变量未设置



我正在尝试从主题指定的电子邮件下载附件。

If Msg.Subject = "CALENDAR-EVENT" Then
        'Download the attachment
        Dim itmAttach As Outlook.MailItem
        Dim objAtt As Outlook.Attachment
        Dim saveFolder As String
            saveFolder = "C:events"
        Dim dateFormat As String
            dateFormat = Format(itmAttach.ReceivedTime, "yyyy-mm-dd Hmm ")
        For Each objAtt In itmAttach.Attachments
            objAtt.SaveAsFile saveFolder & "" & dateFormat & objAtt.DisplayName
        Next
End if

我得到错误:

91对象变量或块变量未设置

也许这条线有错误:

Dim itmAttach As Outlook.MailItem

如果能获得下载文件的名称,那也很好。

我以前没有使用outlook API,多年来也没有接触过VBA,但从外观上看,你的意思是:

If Msg.Subject = "CALENDAR-EVENT" Then
        Dim objAtt As Outlook.Attachment
        Dim saveFolder As String
            saveFolder = "C:events"
        Dim dateFormat As String
            dateFormat = Format(Msg.ReceivedTime, "yyyy-mm-dd Hmm ")
        For Each objAtt In Msg.Attachments
            objAtt.SaveAsFile saveFolder & "" & dateFormat & objAtt.DisplayName
        Next
End if

错误91似乎是VBA的NullReferenceException。

相关内容

  • 没有找到相关文章

最新更新