【问题标题】:Extracting text from Outlook email to Excel - check formatting从 Outlook 电子邮件中提取文本到 Excel - 检查格式
【发布时间】:2017-04-10 09:18:20
【问题描述】:

我正在从电子邮件中提取文本到 Excel,但我遇到了带有特殊字体删除线的文本的问题。提取后它会失去格式,看起来像所有其他文本,但删除线会改变含义。在这种情况下,我需要使用条件,如下所示:

If lines(j).Font.Strikethrough = True Then lines(j) = "Deleted " & lines(j)

有人有这方面的经验吗?

代码的主要部分:

Sub Export_Outlook_Emails_To_Excel()

Dim Folder As Outlook.MAPIFolder
Dim BodyMail As String
Dim lines As Variant
Dim row As Integer
Dim DATA As Worksheet
Dim j, Items As Long

Set DATA = Worksheets("DATA")

'check emails – I deleted not important rows so normally it gioes through all 
emails in directory
Set folder = Outlook.Session.Folders(„Archive“).Folders("Inbox").Folders("Changes")
Items = Folder.Items.Count
BodyMail = Folder.Items.Item(iRow).Body
lines = Split(BodyMail, Chr(9)) ' split multi lines in a cell by TAB 
' EXTRACT DATA FROM EMAIL 
For j = LBound(lines) To UBound(lines) 'export DATA from email into temporary 
DATA sheet        

' --- HERE I NEED INSERT THE CONDITION, SOMETHING LIKE THIS ---
If lines(j).Font.Strikethrough = True Then lines(j) = "Striketrough font : " & lines(j)

DATA.Cells(row, 1) = (lines(j))
Next j

End Sub

【问题讨论】:

  • 代码运行了吗?您可以添加电子邮件正文的示例图像
  • 问题是你的数组只存储文本,没有格式(行=拆分),你需要寻找一种复制整个正文的方法

标签: excel vba email outlook strikethrough


【解决方案1】:

您需要使用HTMLBody 属性而不是纯文本Body 并解析返回的HTML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-01
    • 2022-08-20
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多