0

I am working on a project where I need to get ms access table/data from mail body and execute some command in SAP. I can manage SAP part but issue is that how to get information from mail body. i tried linking my mailbox in access but it shows me all mail body text but i need some specified contents only. example

Hello,
Please supplement budget 
WBS                      Amt
N.10002077.001           1

from above what i need is just "N.10002077.001" and "1" ,but how to get that information only in table is the issue?

Further, what I will get in my mail will be table with 2 column but access imports it as a simple text.

enter image description here

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

1

It is impossible to give a definite answer to your question because it is too vague but it is possible to get you started.

Have a look at this answer of mine: https://stackoverflow.com/a/12146315/973283. The question is not relevant other than the OP did not understand that showing screenshots told us little about what the body looked like to a VBA macro. The answer includes a macro that copies selected properties from every email in Inbox to an Excel worksheet. This will allow you to see what an email’s body looks like to a VBA macro.

How will you identify the emails from which you wish to extract data? The two simple choices are:

  1. Look at every email in a folder and identify the interesting one by examining the subject, sender or some other property.
  2. Select the interesting emails then run a macro which uses ActiveExplorer to access the selected emails.

The answer referenced above demonstrates technique 1. There are lots of answers demonstrating technique 2 but I can add an example macro if necessary.

An email typically has an Html body and a text body. If an email has an Html body, that is the one shown to the user. A macro can access either or both. Your screen shot looks like a text body although appearances can be deceptive. If it is a text body, the email does not have an Html body.

If it is a text body, the layout of the body is probably something like:

Hello,{cr}{lf}
Please supplement budget{cr}{lf} 
WBS{tab}{tab}{tab}{tab}{tab}Amt{cr}{lf}
N.10002077.001{tab}{tab}1{cr}{lf}

This assumes, the sender has used variable numbers of tabs to line up the columns.

You could use Split on vbCr & vbLf to convert the string body into an array of strings with one line per array entry. Discard lines up to and including the line starting “WBS” then process each line down to any signature. Split each line on vbTab and expect to find two entries with values with the rest blank.

See how far you can get with the above hints then clarify your answer if you need more information.

Tony Dallimore
  • 12,335
  • 7
  • 32
  • 61