提取Outlook项目的一部分

时间:2014-02-01 12:31:50

标签: vba outlook

我有一个Outlook项目,其中有很多消息。

是否可以仅提取最后一条消息?使用左功能可能吗?

包含两条消息的主体示例(我只需要提取第一条消息)

**From: dot@dot.com.br
To: aw@yahoo.com.br
Subject: Testing

Hi, this is FIRST test.

Thanks.

John Doe
Telephone: 555 21803**



From: dot@dot.com.br
To: aw@yahoo.com.br
Subject: Testing

Hi, this is the SECOND test.

Thanks.

John Doe
Telephone: 555 21803

1 个答案:

答案 0 :(得分:1)

Sub GetMessageFromMail()

    Dim mi As MailItem
    Dim vaMessages As Variant

    'Get the email item - your method will be different
    Set mi = ActiveInspector.currentItem

    'Split the body into an array. Every time it sees the
    'string 'From:' it creates a new array item
    vaMessages = Split(mi.Body, "From:")

    'The 0th message will be the two asterisks that precede the
    'From: so to get the first message we need the 1 index of
    'our zero based array
    Debug.Print vaMessages(1)

    'Or you could get the last message by using UBound
    Debug.Print vaMessages(UBound(vaMessages))

End Sub