【问题标题】:Using VB Script to read contents of .msg file使用 VB 脚本读取 .msg 文件的内容
【发布时间】:2013-07-30 08:26:50
【问题描述】:

我有一个包含数千个 Outlook .msg 文件的文件夹。

我想知道是否可以编写一个可以从每个文件中读取发送方和接收方的 VB 脚本,并根据此信息将 .msg 文件移动到文件夹中?

谢谢

【问题讨论】:

    标签: vbscript msg


    【解决方案1】:

    除非您期望答案是“是”或“否”,否则您不应该问是/否问题。

    Set ol  = CreateObject("Outlook.Application")
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    For Each f In fso.GetFolder("C:\some\folder").Files
      If LCase(fso.GetExtensionName(f)) = "msg" Then
        Set msg = ol.CreateItemFromTemplate(f.Path)
        WScript.Echo msg.Sender.Name
        For Each rcpt In msg.Recipients
          WScript.Echo rcpt.Name
        Next
      End If
    Next
    

    【讨论】:

      【解决方案2】:

      为了读取 .msg 文件的内容,我使用了以下方法。

      1. 使用 Outlook 对象对 msg 文件使用 CreateItemFromTemplate
      2. 使用此 Outlook 对象将数据保存到 .txt 文件中
      3. 创建 .txt 文件后,读取它并根据需要使用数据

      脚本:

      Dim OL : Set OL=CreateObject("Outlook.Application")
      Dim Msg ':Set Msg= CreateObject("Outlook.MailItem")
      Set Msg = OL.CreateItemFromTemplate("C:\test.msg")
      'MsgBox Msg.Subject
      Msg.saveAs "C:\test.txt", olDoc
      'The above statement will save the contents of .msg file into the designate .txt file 
      
      Set OL = Nothing
      Set Msg = Nothing
      

      创建 .txt 文件后,根据计算需要使用它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-02
        • 2013-07-01
        相关资源
        最近更新 更多