保存附件到磁盘 VBA 代码不起作用


Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
  Dim oAttachment As Outlook.Attachment
  Dim sSaveFolder As String
  sSaveFolder = "C:Usersaxt112Desktopdownloads"
  For Each oAttachment In MItem.Attachments
    If oAttachment = "Checkpoint Volume and Movement Times*" Then oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
  Next
End Sub

我正在使用Outlook VBA代码将带有某些文件的附件保存到指定的文件夹中。规则运行此脚本,我认为规则没有任何问题,因此我认为这是代码。

这很奇怪,因为它上周工作得很好,而且我没有改变任何东西。你们在代码中看到任何奇怪的东西吗?

谢谢。

不能在 VBA 中比较 Outlook 对象和字符串。您可能希望比较 Attachment 类的 DisplayName 属性,该属性返回一个表示名称的字符串,该字符串不必是实际文件名,显示在表示嵌入附件的图标下方。

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
  Dim oAttachment As Outlook.Attachment
  Dim sSaveFolder As String
  sSaveFolder = "C:Usersaxt112Desktopdownloads"
  For Each oAttachment In MItem.Attachments
    If oAttachment.DisplayName = "Checkpoint Volume and Movement Times*" Then          
       oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
    Next
End Sub 

或使用"赞"功能:

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
  Dim oAttachment As Outlook.Attachment
  Dim sSaveFolder As String
  sSaveFolder = "C:Usersaxt112Desktopdownloads"
  For Each oAttachment In MItem.Attachments
    If oAttachment.DisplayName Like "Checkpoint Volume and Movement Times*" Then          
       oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
    Next
End Sub 

您可能会发现 Outlook 2010 中的 VBA 入门 文章很有帮助。

相关内容

最新更新