【问题标题】:Extract Outlook body to Excel VBA将 Outlook 正文提取到 Excel VBA
【发布时间】:2015-02-13 12:45:51
【问题描述】:

在搜索了多个东西并得到错误之后 如何在 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

还有一些,去年。

【问题讨论】:

  • 到目前为止你有什么?你有没有尝试过?

标签: excel vba outlook


【解决方案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

【讨论】:

  • 感谢您的帮助,这将保存到哪里,如何保存?我在 dim objdoc as word.document 中也遇到编译错误
  • 您需要设置对 Word 和 Excel 对象库的引用
  • 那么,我需要参考“test.xlsx”和“test.doc”吗?
  • no in the VBA editor under tools > references> 检查 Microsoft Word 对象库和 Microsoft Excel 对象库。见以下链接google.com/…
  • 今天回去工作,听从了你的建议,完美的工作,谢谢
【解决方案2】:

Outlook 对象模型无法识别正文中的线条。您可以尝试调整 Outlook 中的任何检查器窗口的大小,并查看正文线条的变化情况。

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

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

【讨论】:

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