【问题标题】:How to send outlook msg files to excel如何将outlook msg文件发送到excel
【发布时间】:2016-04-25 14:33:17
【问题描述】:

以下代码允许我将 .msg 文件导入 excel。 我想知道是否可以在 Outlook 中创建一个将消息发送到 excel 文件而不是导入它们的宏。

我用来导入.msg文件的代码如下:

Sub IMPORTMSG()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False

    Dim i As Long
    Dim inPath As String
    Dim thisFile As String
'    Dim Msg As MailItem
    Dim ws As Worksheet
'    Dim myOlApp As Outlook.Application
'    Dim MyItem As Outlook.MailItem

    Set myOlApp = CreateObject("Outlook.Application")
    Set ws = ThisWorkbook.Worksheets("A")

    With Application.FileDialog(msoFileDialogFolderPicker)
       .AllowMultiSelect = False
            If .Show = False Then
                Exit Sub
            End If
        On Error Resume Next
        inPath = .SelectedItems(1) & "\"
    End With
    thisFile = Dir(inPath & "*.msg")
    i = 4
    Do While thisFile <> ""
            Set MyItem = myOlApp.CreateItemFromTemplate(inPath & thisFile)
        If MyItem.Subject = "testheader" Then
            ws.Cells(i, 1) = MyItem.Body
            i = i + 1
        End If
            thisFile = Dir()
    Loop

    Set MyItem = Nothing
    Set myOlApp = Nothing

    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
End Sub

【问题讨论】:

  • “发送”是什么意思? MSG 文件的创建方式和原因是什么?
  • @DmitryStreblechenko |来自不同部门的用户以特定格式发送有关问题的邮件。现在我将这些邮件保存到一个文件夹并将它们导入到 excel 中。我想知道是否可以在 Outlook 中点击一个按钮,将这条消息发送/导出到一个名为“reportsA”的 excel 文件中

标签: vba outlook


【解决方案1】:

您可以为 Outlook 创建一个 COM 插件并让它运行上面的代码。或者您可以在 Outlook 中使用Application.ActiveExplorer.Selection 集合来循环浏览 Outlook 中的选定邮件,而不是处理独立的 MSG 文件。

【讨论】:

    【解决方案2】:

    您可以开发一个 Outlook VBA 宏,您可以在其中自动执行 Excel 并设置 Excel 单元格值。请参阅How to automate Microsoft Excel from Visual Basic 了解更多信息。

    您还可能会发现Getting Started with VBA in Outlook 2010 文章很有帮助。

    【讨论】:

      猜你喜欢
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 2014-12-25
      • 2016-11-19
      • 2019-05-07
      • 2015-09-03
      • 2013-05-27
      相关资源
      最近更新 更多