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
 
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.
Similar threads
Thread starter Title Forum Replies Date
C Wishlist Extract or scan new email addresses from out of office replies. Leads from OOO replies Using Outlook 1
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
S Unable to extract text from an Outlook email message Using Outlook 2
S Macro to extract and modify links from emails Outlook VBA and Custom Forms 3
S Macro to extract email addresses of recipients in current drafted email and put into clipboard Outlook VBA and Custom Forms 2
C Macro to extract sender name & subject line of incoming emails to single txt file Outlook VBA and Custom Forms 3
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
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
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
E Edit incoming emails to remove a certain sentence added by the "system" Using Outlook 1
F Color code certain INBOX emails Using Outlook 2
CWM330 Saving Data: Don't check certain folders Using Outlook 2
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
P Emails assigned with a certain category (within a shared inbox) to be copied to a specific folder. Outlook VBA and Custom Forms 2
N Save emails within a certain date range to network drive Outlook VBA and Custom Forms 0
A Outlook Reminders not populating for certain events Using Outlook 2
D Cannot populate certain UserProperties in Outlook from Excel Outlook VBA and Custom Forms 2
S Visual indicator of a certain property or to show a macro toggle Outlook VBA and Custom Forms 2
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2

Similar threads

Back
Top