0

I am looking for some code to pull values from the body of an outlook message. I will set up the whole situation I need below:

  • An email is sent with specific subject and certain values in body. -Subject could be "Test" -In body of email it would be: Name: (name here changes) Number: (number here changes)

I can set up the Excel file I need to open after this email is received, but what I need is for that Excel file that opens, to look back at that email message and pull the name and number (that can change) into cells A1 and B1.

Keep in mind that there will be multiple emails coming through with this same format, so it should only look in message that was just sent a minute or two ago.

Is this possible? Any help would be greatly appreciated. Thanks.

Community
  • 1
  • 1
user3456594
  • 29
  • 1
  • 3
  • Yes it is possible. `I am looking for some code to pull values from the body of an outlook message`. What have you tried? And how does your email body look like? It is essential to give us more information about how you try to solve your problem. – L42 Apr 26 '14 at 14:54
  • Look at the `outlook-vba` questions and answers. You will find code that looks at each new message and code that writes to Excel. Try to develop something then come back if you run into difficulties. – Tony Dallimore Apr 27 '14 at 11:40

1 Answers1

0

Since the triggering action is the receipt of an email, I would suggest that you focus on having Outlook running the script when the message is received and then pushing the information to the Excel sheet. Here is something that will get you started.

You will want to make sure that there is a way to easily identify where the name field is on the email body too, possibly wrapping it like [[NAME]] Person Name Here.

Community
  • 1
  • 1
Adach1979
  • 278
  • 2
  • 8
  • This code from your link works great, I just cannot figure out two things. First, instead of adding the subject, I want to add some values from the body of the email. The format will always be the same. How would I do that even if I wrapped the [[Name]] like you said? I am very unfamiliar with Outlook codes/references. Also, my end goal is to have Excel run something based on those values that come from the message. Is there a way to have the file open and stay open so I can run a different Excel Macro? – user3456594 Apr 28 '14 at 21:16
  • Forget the second part, I realized I can just create a rule to open the file, so that should work. I guess my only question left, is: how would I add 4 values in the body of the email, that would stay consistent in every message sent? These 4 values would be the four values exported to the Excel file. The 4 are below: [[First Name]] (first name here) [[Last Name]] (Last name here) [[email address]] (Email address here) [[Store Number]] (Store number here) – user3456594 Apr 28 '14 at 21:22
  • To keep Excel open after running the code in the link I sent you remove the lines `oXLwb.Close (True)` and `oXLApp.Quit`. As for how you would add the 4 values to the email, how is the mail message getting populated? a Web form, users typing the message? You could look into using an Outlook form or InfoPath form for collecting the data. [Here is a link](http://msdn.microsoft.com/en-us/library/office/ff868929(v=office.15).aspx) to how to create Outlook forms as another starting point. – Adach1979 Apr 29 '14 at 12:50