首页 > 解决方案 > 如何从电子邮件中提取数据?

问题描述

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

您的 EagleView 测量已准备好接受以下订单:
•<br /> • 报告 ID:26048369(高级版,60.00 美元,4740 平方英尺)
• 地址:123 Apple St, City, FL 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

标签: vbaoutlook

解决方案


'Address' 是一个字符串数组,因此当您尝试显示它时会引发错误。您需要数组的第四个元素,它是零索引的。只需替换MsgBox "The Address is: " + AddressMsgBox "The Address is: " + Address(3)


推荐阅读