如何从电子邮件中提取数据

时间:2018-12-07 19:13:37

标签: vba outlook

我收到的电子邮件中包含以下数据:

您的EagleView Measurement已准备好按以下顺序进行: •
•报告ID:26048369(附加费,$ 60.00,4740平方英尺) •地址:佛罗里达州城市Apple街123号32456-####

我需要使用街道地址“ 123 Apple St”,并将其放入一个变量中,以便稍后调用。

运行时出现运行时错误13不匹配的类型。这是我正在使用的代码“

Sub Extract()
'Define Variables
Dim sFileName As String
Dim Address As Variant

Set myfolder = Outlook.ActiveExplorer.CurrentFolder

For i = 1 To myfolder.Items.Count
Set myitem = myfolder.Items(i)
msgtext = myitem.Body

'Search for specific Text
delimitedMessage = Replace(msgtext, "Address: ", "###")
delimitedMessage = Replace(delimitedMessage, ",", "###")
Address = Split(delimitedMessage, "###")

'Alert box showing if the code worked
MsgBox "The Address is: " + Address

Next
End Sub

在此先感谢您提供的帮助!

1 个答案:

答案 0 :(得分:0)

“地址”是一个字符串数组,因此当您尝试显示它时会抛出错误。您需要数组的第四个元素,该元素为零索引。只需将MsgBox "The Address is: " + Address替换为MsgBox "The Address is: " + Address(3)