将Outlook正文提取到Excel VBA

问题描述 投票:0回答:2

搜索多个内容并获取错误如何在vba脚本中按“f5”将电子邮件正文复制到Excel工作表/ csv中,其中每行=下面的新单元格。

谢谢

对不起,这只会给我带来麻烦。我到目前为止尝试过http://smallbusiness.chron.com/export-outlook-emails-excel-spreadsheets-41441.html

How to copy Outlook mail message into excel using VBA or Macros

http://www.vbforums.com/showthread.php?415518-RESOLVED-outlook-the-macros-in-this-project-are-disabled

http://www.ozgrid.com/forum/showthread.php?t=181512

还有一些,去年。

vba outlook-vba
2个回答
1
投票

这对你有用。我们基本上将电子邮件正文拆分为基于新行的数组。请注意,如果电子邮件正文中有空行,则会生成空白单元格。

Public Sub SplitEmail() ' Ensure reference to Word and Excel Object model is set
    Dim rpl As Outlook.MailItem
    Dim itm As Object
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set rpl = itm.Reply
        rpl.BodyFormat = olFormatHTML
        'rpl.Display
    End If
    Dim objDoc As Word.Document
    Set objDoc = rpl.GetInspector.WordEditor
    Dim txt As String
    txt = objDoc.Content.text
    Dim xlApp As Excel.Application
    Set xlApp = CreateObject("Excel.application")
    xlApp.Visible = True
    Dim wb As Excel.Workbook
    Set wb = xlApp.Workbooks.Add
    Dim i As Long
    For i = LBound(Split(txt, Chr(13)), 1) To UBound(Split(txt, Chr(13)), 1)
        wb.Worksheets(1).Range("A" & i + 1).Value = Split(txt, Chr(13))(i)
    Next i
End Sub
Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
    Case "Explorer"
    Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
    Case "Inspector"
    Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
    GetCurrentItem.UnRead = False
    Set objApp = Nothing
End Function

0
投票

Outlook对象模型无法识别正文中的行。您可以尝试在Outlook中调整任何检查器窗口的大小,并查看正文行的更改方式。

无论如何,您可以尝试使用Word对象模型来获取确切的行。 Outlook使用Word作为电子邮件编辑器。 Inspector类的WordEditor属性返回表示消息正文的Document类的实例。您可以在Chapter 17: Working with Item Bodies文章中阅读有关所有可能方法的更多信息。

How to automate Microsoft Excel from Visual Basic文章解释了如何从任何外部应用程序自动化Excel。

© www.soinside.com 2019 - 2024. All rights reserved.