Outlook VBA - grabbing info from email form

Associate
Joined
23 Mar 2009
Posts
348
Location
Midlands
Hi all,

I have a form on the company intranet which emails me the form data in the below format.
What I want to do is for it to auto-reply to the email address that the user submitted with a URL to a website.

I don't have access to the form and the form results get sent from a static email address, so it will have to grab the data from the message body - is this possible?

Code:
Store xxxx (Manchester) has submitted a new "Website Link" form. A summary of the data is shown below.

First name: 			John
Last name: 			Smith
Email address: 			[email protected]
 
Have this so far:
Code:
Public Sub ExtractEmail()
Dim obj As Object
Dim Items As Outlook.Items
Dim Folder As Outlook.MAPIFolder
Dim i As Long
Dim Pos1 As Long, Pos2a As Long, Pos2b As Long
Dim SMiddle As String

Set Folder = Application.Session.GetDefaultFolder(olFolderDrafts)
Set Items = Folder.Items
For i = 1 To Items.Count
Set obj = Items(i)
Pos1 = InStr(1, obj.Body, "@", vbTextCompare)
Pos2a = InStr(1, obj.Body, "Email address:", vbTextCompare)
Pos2b = InStr(1, obj.Body, "Please click this", vbTextCompare)
If Pos1 > 0 Then
If Pos2a > 0 Then
If Pos2b > 0 Then
Pos2 = Pos1 + Len("@")
SMiddle = Mid$(obj.Body, Pos2a + 19, 20)
MsgBox (SMiddle)
End If
End If
End If
Next
End Sub

So SMiddle currently returns the text 20 characters either side, but what I really need it to do is return everything between the @ and the nearest space.
 
Back
Top Bottom