用于从Outlook下载附件,将其保存在桌面上并打开它的代码 [英] Code to download attachment from Outlook, save it on desktop and open it

查看:148
本文介绍了用于从Outlook下载附件,将其保存在桌面上并打开它的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is the code in Outlook that sets the rules in Outlook automatically to save the attachment (Excel) with date stamp:

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

下一步,我要保存的附件是打开附件.有可能吗?

Next step I want is to open the attachment once it's saved. Is that possible?

这个怎么样?

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)

结束子

推荐答案

是的,有可能.如果您确切知道需要打开Excel文件,则可以使用Excel对象模型来完成工作.有关更多信息,请参见如何从Visual Basic自动化Microsoft Excel 信息. 打开方法Workbooks类将打开一个工作簿.

Yes, it is possible. If you know exactly that you need to open Excel files you may use the Excel object model to get the job done. See How to automate Microsoft Excel from Visual Basic for more information. The Open method of the Workbooks class opens a workbook.

这篇关于用于从Outlook下载附件,将其保存在桌面上并打开它的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆