将Outlook电子邮件中的文本提取到Excel - 检查格式

时间:2017-04-10 09:18:20

标签: excel vba email outlook strikethrough

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

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

1 个答案:

答案 0 :(得分:1)

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