【问题标题】:How to save Outlook mails as .msg file with categories and other details?如何将 Outlook 电子邮件保存为带有类别和其他详细信息的 .msg 文件?
【发布时间】:2017-11-25 06:40:37
【问题描述】:

使用 MailItem.SaveAs 在 Outlook VBA 中保存电子邮件很容易

但我没有看到任何保存其他详细信息的选项,例如作者和类别。

第 3 方程序 MessageSave 允许以 .msg 格式保存带有类别和作者的邮件。在 Windows 资源管理器中,作者和类别列显示与 Outlook 中相同的信息。

有人知道如何使用 Outlook VBA 保存邮件,包括这些附加信息吗?

我买了 MessageSave,它是一个很好的程序,但是他们不允许在 VBA 中使用他们的保存功能。唯一的解决方法是让 MessageSave 在消息“到达”特定文件夹时保存它们。如有必要,我可以使用此功能,但这只是一种解决方法。

以下是使用 MessageSave 保存的电子邮件如何在 Windows 资源管理器中显示的示例:

【问题讨论】:

  • Outlook 保存项目时也会保存附加信息。它只是没有出现在资源管理器中,因为它都在味精文件内部,资源管理器不会费心去那里看。 MessageSave 似乎还设置了扩展属性,这些属性是文件系统的一个特性,并且存储在文件的外部。可以在MessageSave创建了几个文件的目录下,在命令行中运行dir /r | find ":$DATA"吗?
  • 感谢您的评论。当我运行该命令时,它不会返回任何文件。
  • 当您在资源管理器中打开文件属性时,额外的属性是否会显示在任何地方?究竟在哪里?
  • 我刚刚添加了截图
  • 没有。 “当你在资源管理器中打开文件属性时”表示鼠标右键->属性。

标签: vba email outlook


【解决方案1】:

这里有一个更实用的脚本

没有错误检查

不检查重复的邮件名称

不检查非法文件名(“:”字符除外)

只需在任何 Outlook 文件夹中选择一堆电子邮件并运行它

' make sure you have a reference to "DSO OLE Document Properties Reader"

Sub extendedProperties()

    Dim msg As mailItem
    Dim objFile As OleDocumentProperties

'   Set objFile = CreateObject("DSOFile.OleDocumentProperties")
    Set objFile = New OleDocumentProperties

    Dim fileName As String
    Dim subjectText As String

    ' !!!!!!!! select a bunch of messages before running this !!!!!!!!

    For Each msg In ActiveExplorer.Selection

        subjectText = Replace(msg.Subject, ":", "_")   ' get rid of illegal file name character (there are others)

        ' adjust the destination folder for your liking
        fileName = "C:\Users\js\Desktop\testFiles\" & subjectText & ".msg"

        Debug.Print fileName

        msg.SaveAs fileName

        objFile.Open fileName
        objFile.SummaryProperties.Subject = "My Subject"
        'objFile.Save
        objFile.Close True     ' save and close   !!!!! duplicate filenames get overwritten !!!!!

'   stop                       ' uncomment this line and the code will stop. press F5 to run, F8 to single-step

    Next msg

    Set msg = Nothing
    Set objFile = Nothing

End Sub

【讨论】:

    【解决方案2】:

    这是我遵循的一个过程:(win7 64)

    网页搜索“windows vba设置扩展文件属性”

    第一次点击:StackOverfow 16989882

    网络搜索:“DSOFile.OleDocumentProperties”

    点击 microsoft:Dsofile.dll 文件可让您在未安装 Office 时编辑 Office 文档属性

    https://support.microsoft.com/en-us/help/224351/the-dsofile.dll-files-lets-you-edit-office-document-properties-when-yo

    这不是错字...它以“when-yo”结尾

    下载:DsoFileSetup_KB224351_x86.exe

    使用 7-zip 程序(来自 7-zip.org)打开 DsoFileSetup_KB224351_x86.exe

    将 dsofile.dll 从 DsoFileSetup_KB224351_x86.exe(使用 7-zip)复制到文件夹桌面(在本例中名为“testFiles”)(这可以在任何地方......也许是 windows system32 或 syswow64......我只试过桌面)

    以管理员身份打开命令提示符窗口

    导航到包含 dsofile.dll 的文件夹

    执行以下:regsvr32 dsofile.dll

    应该会收到成功确认

    启动 Outlook ... vba 编辑器 ... 工具 ... 参考

    并找到“DSO OLE Document Properties Reader 2.1”并选中左侧的框

    返回 vba 编辑器...创建新模块

    粘贴以下内容:(这只是一个最小的测试脚本)

    Sub extendedProperties()
    
        Dim objFile As OleDocumentProperties
        Set objFile = CreateObject("DSOFile.OleDocumentProperties")
    
        objFile.Open ("C:\Users\js\Desktop\testFiles\myMessage.msg")  ' adjust to match your system
        objFile.SummaryProperties.Subject = "My Subject"
        objFile.Save
    
        Set objFile = Nothing
    End Sub
    

    将电子邮件“myMessage”从 Outlook 复制(拖放)到文件夹(在本例中为桌面)

    右键单击文件夹列标题...点击更多...找到“主题”... 点击复选框

    运行脚本

    主题列应在 myMessage.msg 旁边包含“我的主题”(或任何您的消息名称)

    可能有更简单的方法...也许 windows PowerShell 有一个可以从 vba 调用的命令

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-17
      • 2019-04-24
      • 2021-07-30
      • 2017-04-27
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多