extract certain text from an Outlook Email Message

Status
Not open for further replies.

kadiva

New Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
Hi Diane,

Nice to meet you, I'm new here at the forum. I need your help regarding a task I've been assigned to extract certain text from an Outlook Email Message when it arrives through inbox to a specific folder. I followed your directions as best as I can on your Blog post "slipstick.com to extract the following information but had some difficulty:

Please view if I've coded the information correctly to retrieve the information, Thanks Diane I appreciate your help.

Sub GetValueUsingRegEx()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strSubject As String
Dim testSubject As String
Set olMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp

For i = 1 To 15

With Reg1
Select Case i
Case 1
.Pattern = "(Title[:]([\w-\s]*)\s*)\n"
.Global = False
Case 2
.Pattern = "(First Name[:]([\w-\s]*)\s*)\n"
.Global = False
Case 3
.Pattern = "(Last Name[:]([\w-\s]*)\s*)\n"
.Global = False
Case 4
.Pattern = "(Address[:]([\w-\s]*)\s*)\n"
.Global = False
Case 5
.Pattern = "(City[:]([\w-\s]*)\s*)\n"
.Global = False
Case 6
.Pattern = "(Province[:]([\w-\s]*)\s*)\n"
.Global = False
Case 7
.Pattern = "(Postal Code[:]([\w-\s]*)\s*)\n"
.Global = False
Case 8
.Pattern = "(Phone Number[:]([\w-\s]*)\s*)\n"
.Global = False
Case 9
.Pattern = "(Email Address[:]([\w-\s]*)\s*)\n"
.Global = False
Case 10
.Pattern = "(Age Range[:]([\w-\s]*)\s*)\n"
.Global = False
Case 11
.Pattern = "(Do You Have A Spouse or Partner?[:]([\w-\s]*)\s*)\n"
.Global = False
Case 12
.Pattern = "(Number of dependants[:]([\w-\s]*)\s*)\n"
.Global = False
Case 13
.Pattern = "(Free online course[:]([\w-\s]*)\s*)\n"
.Global = False
Case 14
.Pattern = "(My renewal within the next[:]([\w-\s]*)\s*)\n"
.Global = False
Case 15
.Pattern = "(Like to have an professsional evaluation ?[:]([\w-\s]*)\s*)\n"
.Global = False
Case 15
.Pattern = "(([\d]*\.[\d]*))\s*\n"
.Global = False
End Select

End With
If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
For Each M In M1
Debug.Print M.SubMatches(1)
strSubject = M.SubMatches(1)
strSubject = Replace(strSubject, Chr(13), "")
testSubject = testSubject & "; " & Trim(strSubject)
Debug.Print i & testSubject
Next
End If

Next i

Debug.Print olMail.Subject & testSubject
olMail.Subject = olMail.Subject & testSubject
olMail.Save

Set Reg1 = Nothing

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Does it work? :) Use Ctrl+G to show the immediate window - debug.print will add the collected values there so you can see if it works. If it gets the correct information then half the battle is won.

The code works on the selected item (assuming it works) - do you want it to run automatically?
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
N Extract Outlook emails to excel Outlook VBA and Custom Forms 2
M Extract all links from Outlook email, send to Excel Using Outlook 2
T Extract Data From Outlook Tasks Using Outlook 0
T Extract Data From Outlook Tasks Using Outlook 0
V extract users of a particular department Outlook VBA and Custom Forms 1
J Outlook 2013 Extract Flag Completed dates to Excel Macro Outlook VBA and Custom Forms 16
S How to extract mail items from multiple folders and shared mailboxes? Outlook VBA and Custom Forms 0
K Extract email address from body and auto-reply outlook Using Outlook 1
R Trying to extract information between two symbols from outlook subject Using Outlook 2
K Extract email to excel from a specific sender Outlook VBA and Custom Forms 3
O VBA to extract email (fields and body) to Excel Outlook VBA and Custom Forms 14
P Recover / Extract Rules from standalone PST file creating RWZ file Using Outlook 2
B Extract Dates for Appointment Item in Body of email Outlook VBA and Custom Forms 10
D Need to extract a line from a word attachment, and add it to the subject line Outlook VBA and Custom Forms 3
E Extract excel files from outlook Outlook VBA and Custom Forms 2
D VBA Script to extract text matching specific criteria Outlook VBA and Custom Forms 1
M Extract text in existing message body for use in newmail items Using Outlook 17
M HELP--Extract Data from 2003 outlook transfer to excel spreadsheet Using Outlook 1
M VBA Code to extract data from an Outlook Form Using Outlook 0
M Extract attachments with a script Using Outlook 0
M HELP - Can't open outlook... How can I extract my Emails that I had in folders Using Outlook 3
H Extract emails from Outlokk 2007 email body Using Outlook 0
K Extract Global Address List Using Outlook 1
E I am trying to extract the email adress's i have in outlook. These are not saved 'contacts' these are ones from auto fill. When i open up an email, an Using Outlook 1
L How to extract table format of Task Item if its body contains formatted table. Exchange Server Administration 1
D Extract email addresses from inbox in a batch and move them into "bcc" for a mass email campaign Using Outlook 1
M Extract, zip and replace attachement in each message of a pst file Using Outlook 0
R Saving Outlook Email As Text File Extract Outlook VBA and Custom Forms 2
N Programming to extract automatically extract attachments Outlook VBA and Custom Forms 3
S How to extract outlook calendar data. Outlook VBA and Custom Forms 3
? outlook attachment Extract File ??? Outlook VBA and Custom Forms 1
D Extract Data from OST File Using Outlook 2
N How to extract date and time stamp from messsages Outlook VBA and Custom Forms 6
V Extract Subject,Sent From, Message from mailbox to Excel Outlook VBA and Custom Forms 5
S Automatically extract attachments? Outlook VBA and Custom Forms 1
I How to extract email addresses from TO or CC line of a particular email Outlook VBA and Custom Forms 2
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
T Outlook 2016 remove envelope icon for certain folders Using Outlook 6
B Outlook 2010 Can not find a certain file in M/S Outlook 2010. Using Outlook 1
S Unable to Edit Contact Information in Certain Contact Folders Using Outlook 3
F How to show assigned tasks under certain mailbox? Using Outlook 4
B When working on emails in a certain folder, when I hit reply or reply all, I would like it re always reply all and add an email address to send to Outlook VBA and Custom Forms 3
N Syncing my inbox not working for certain types of mail Using Outlook 9
C VBA to Forward e-mails from certain address and between certain times Outlook VBA and Custom Forms 1
avant-guvnor Unable to view certain emails in Outlook 2016 Using Outlook 16
skyfox VBA to search email subject field for a certain string Outlook VBA and Custom Forms 3
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
J Autoforward emails to different contacts based on certain criteria using only one rule Using Outlook 1
E Send a Reminder/Task to certain Email Recipient Using Outlook 5
P move a specified email "From" tag items to a certain folder whenever there is "New Mail" in the inbo Outlook VBA and Custom Forms 5
Similar threads


















































Top