首页 文章

如何将 Outlook 邮件另存为带有类别和其他详细信息的.msg 文件?

提问于
浏览
1

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

但是我看不到任何其他选项来保存其他详细信息,例如 i.e。作者和类别。

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

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

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

这是一个示例,如何使用 MessageSave 保存的电子邮件在 Windows 资源管理器中显示:
在此处输入图片说明

2 回答

  • 0

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

    Web 搜索“ 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 文档属性阅读器 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 复制(拖放)到文件夹(在此示例中为台式机)

    文件夹列标题上的 right-click ...单击更多...查找“主题” ...单击复选框

    运行脚本

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

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

  • -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
    

相关问题