从Outlook下载附件的代码,将其保存在桌面上并打开它

时间:2015-04-28 17:35:20

标签: excel vba outlook-vba outlook-2010

这是Outlook中的代码,它自动设置Outlook中的规则以使用日期戳保存附件(Excel):

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat

    dateFormat = Format(Now, "yyyy-mm-dd H-mm")
    saveFolder = "c:\Users\abc1\Desktop\"
   For Each objAtt In itm.Attachments
      objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
      Set objAtt = Nothing
 Next

End Sub

我想要的下一步是在保存后打开附件。这可能吗?

这个怎么样?

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
  Dim objAtt As Outlook.Attachment
  Dim saveFolder As String
  Dim dateFormat

      dateFormat = Format(Now, "yyyy-mm-dd H-mm")
      saveFolder = "c:\Users\abc1\Desktop\"
     For Each objAtt In itm.Attachments
        objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
        Set objAtt = Nothing
   Next


Dim Shex As Object
   Set Shex = CreateObject("Shell.Application")
   tgtfile = "objatt"
   Shex.Open (tgtfile)

End Sub

1 个答案:

答案 0 :(得分:1)

是的,有可能。如果您确切知道需要打开Excel文件,则可以使用Excel对象模型完成工作。有关详细信息,请参阅How to automate Microsoft Excel from Visual Basic。 Workbooks类的Open方法打开工作簿。