簡體   English   中英

將 Outlook 正文提取到 Excel VBA

[英]Extract Outlook body to Excel VBA

在搜索多項內容並出現錯誤后,如何在 vba 腳本中按“f5”將電子郵件正文復制到 Excel 表 /csv 中,其中每一行 = 下面的一個新單元格。

謝謝

對不起,這只會給我帶來麻煩。 到目前為止我嘗試過的http://smallbusiness.chron.com/export-outlook-emails-excel-spreadsheets-41441.html

如何使用 VBA 或宏將 Outlook 郵件消息復制到 Excel 中

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

還有一些,去年。

這對你有用。 我們基本上是將電子郵件正文拆分為基於新行的數組。 請注意,如果電子郵件正文中有空行,這將產生空白單元格。

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

Outlook 對象模型無法識別正文中的線條。 您可以嘗試在 Outlook 中調整任何檢查器窗口的大小,並查看正文線條是如何更改的。

無論如何,您可以嘗試使用 Word 對象模型來獲取准確的線條。 Outlook 使用 Word 作為電子郵件編輯器。 Inspector 類的WordEditor屬性返回表示消息正文的 Document 類的實例。 您可以在第 17 章:使用項目實體一文中閱讀有關所有可能方式的更多信息。

如何從 Visual Basic 自動化 Microsoft Excel 一文解釋了如何從任何外部應用程序自動化 Excel。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM