MS Access | How to get content from mail body to table? - vba

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.

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:
Look at every email in a folder and identify the interesting one by examining the subject, sender or some other property.
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.

Related

Replace zero length mail merge field with user input

I have a MS Word template where I have certain mail-merge fields and one of those fields in the source doucment is sometimes empty. I am using below IF condition and taking user's input for the date field but I cannot update the source mail merge document with this information.
If Len(ActiveDocument.MailMerge.DataSource.DataFields("startDate").Value) < 1 Then
InputStartDate = Format(InputBox("Enter Commenced date ..."), "mm/dd/yyyy")
ActiveDocument.MailMerge.DataSource.DataFields("startDate").Value = InputStartDate
End If
I get an error here that says mail merge source doucment field connot be edited or is locked, something like this.
Is there any way through which I could either update the source field and through application refresh method, I populate that mail merge field with this user input date?
Alternatively I could otherwise add a few lines of code to perform following steps:
1- Save this document (using Saveas2 method) as ".docx" by converting it from ".docm"
2- Break the mail merge connection through VBA code
3- Select all mail merge fields and using Sendkeys "CTRL+SHIFT+F9" covert all of them to normal strings.
4- Make that particular mail-merge field a Bookmark field and then finally update that bookmark field with the user input.
This sounds like a longer route of getting a simple empty mail merge field issue fixed but this is so far all that I could think of. If you have any better suggestion, please let me know.
Instead of vba, do this with fields. Then it becomes part of the Mail Merge.
{ IF { MergeField startDate } > 0 "{MergeField starttDate }" "{ FillIn "What is the Start Date?" }" }
This will trigger the Fill-In field unless there is content in the startDate field for the record.
Here is documentation on the Fill-In Field.
Here is documentation on the IF Field.
Here is my tutorial on the Ask and Fill-In Fields.
Here is my article on Dealing With Fields in Microsoft Word.
Here is Word MVP Paul Edstein's Tutorial on Mailmerge Tips and Tricks.

Outlook/VBA - find UID in Subject and run search for UID in Mail items

I've been in and out of so many Microsoft docs and forums SEARCHING for the answer, I figured I'd just ask.
Long story short - I want to write a macro that, with an email highlighted in the main/mail pane in Outlook ...
Searches the subject line of the email for the case number/UID (always a four digit year, hyphen, and a six digit number, e.g., 2019-012345); and then
runs a basic search (not Advanced Find) in my inbox and all subfolders for any email with that UID in the subject line or body.
I'd offer a jumping off point but Outlook doesn't have a record macro function.
Functionally speaking ... my Outlook search option is set to include results from all folders. I hit Ctrl-E and type in the UID and hit enter to search. Would love to reduce that to one key stroke
Does the code have to get into DASL and MAPI? The extent of my VBA knowledge goes to user forms and template letters so ... I'm in way over my head.

Microsoft Word VBA - IF & THEN Find word and print in another sheet

I am a bit of novice when it comes to VBA (mostly navigate through the code by Recording actions and then altering it accordingly to what I need).
My current problem is the following:
I am going to compile hundreds of word Docs that contain email addresses from clients that I need. In order to make this as easy as possible, I would like to have some code that finds their emails AND additional information that surrounds the email addresses (Name, Location,Job Title,and [possibly] Phone Number) and then copies and pastes the mentioned info to another designated document. The documents and the abovementioned info are formatted as such :
FirstName LastName
Location
Job title # Company
email address - phone number
Now, I believe this will include and IF/THEN statement since not all clients have their email addresses in the documents.
So, IF there is an email address THEN copy it along with the 3 lines above and the phone number that is separated by "a space" "-" "a space"AND paste it on another sheet. IF there is no email address, then keep going.
This query code will probably include a FIND that needs to have a "#" and ".com" attached to the same string. This will be needed since the document also includes other text that has ".com" and "#" but not together.
This sounds harder than what it really is, but again I'm a novice so not completely sure. Feel free to ask any additional questions!
This is an extremely broad question, but I suggest you do the following:
Use a Scripting.FileSystemObject to iterate through files in a folder, looking for Word documents
Open the document using the Word Automation object model
Application object
Application.Documents property, and Documents collection
Documents.Add method, and the Document object, to create the destination document
Documents.Open method, to open existing documents
Find emails within the document (via the Document.Content property, and the Range object)
Range.Find property and the Find object
If the Find.Execute2007 method returns true, then:
Extend the range to the previous 3 paragraphs
Range.MoveStart method
Copy and paste the range to the destination document
You can write only the text to the destination document — Range.Text property, and the Range.Insert-* methods
Or, you can use the clipboard Range.Copy and Range.Paste
Or, you can export to an external file (Range.ExportFragment) and later import from the external file (Range.ImportFragment)

VB, Outlook Macro: How to put variable, (fields), in an email template

I have a simple macro that reads Strings from a .csv file. I want to place (Replace) those Strings into the body of an email. The email will be opened from a template, so I want the fields in the template, and then have my macro start a new email from the template and replace the fields with the String variables.
I'm not finding anything posted that shows how to format such a field in the body of the email.
A link to a reference would be helpful.
The rest of the story: The email template body was pasted from a Word mailmerge document, so it already has mailmerge fields in the correct locations. There is probably a way to make mailmerge work in Outlook, but mailmerge in Word was problematic, and I don't know what makes mailmerge tick, so when it broke on a user's computer I had to rebuild the merge document, etc. Now we're switching to email instead of a printed Word document, and I'm more comfortable with writing a macro to explicitly place the data. I haven't done much programming in vba, so I'm picking up the syntax piece by piece as I go.
There are no fields. Your Outlook .oft template should contain unique string placeholders.
Once you .CreateItemFromTemplate, replace the unique string placeholders.
MyMail.HTMLBody = Replace(MyMail.HTMLBody, "UniqueStringPlaceholder_1", "csvstring_1")
You will likely work out some kind of loop.

How do I access one entry in a mail merge document?

I have set up a mail merged XtraReport, and it works fine. Now I want to access one entry in that mail merged report. By entry I mean the text associated with one row in the dataset, i.e. with the values filled in instead of having the square brackets with the field names.
So if have an XRRichText in my report with the text "Hi [name]" I want access to the XRRichText object with the RTF value "Hi Sandy"
Edit: Added information in example, added VB.net tag
Try the GetCurrentColumnValue method described here.