Hi Guys
This is an awesome script, works brilliantly.
Is there a way to make it collect multiple emails out of the body of an email instead of stopping at the first one?
thank you for any assistance.
Hi Guys
This is an awesome script, works brilliantly.
Is there a way to make it collect multiple emails out of the body of an email instead of stopping at the first one?
thank you for any assistance.
Do you mean multiple email ADDRESSES from the body of a message. Take a look at http://www.gmayor.com/extract_data_from_email.htm for an approach that can easily be configured to do so - also see http://www.gmayor.com/extract_email_data_addin.htm
Graham Mayor - MS MVP (Word) 2002-2019
Visit my web site for more programming tips and ready made processes
http://www.gmayor.com
Hi gmayor, thank you for the links, those look very useful.
What I am looking for is exactly the script on here, but instead of it just removing the first email I need to it extract all the email addresses in the body of the email.
This script seems to stop after it gets the first email address.
Thank you for your help.
this is not my script and i have not tested this modification, but try like
ReDim badAddresses(1 to 1) As String ' initialize variant position counter i = 1 ' parse each message in the folder holding the bounced emails For Each Item In olFolder.Items strBody = olFolder.Items(i).Body Set olMatches = regEx.Execute(strBody) If olMatches.Count >= 1 Then redim preserve badaddresses(1 to ubound(badaddresses) + olmatches.count - 1) ' check this gives correct result for m = 0 to olmatches.count -1 badAddresses(i) = olMatches(m) i = i + 1 Item.UnRead = False next End If Next Item
Hi westconn1, thank you for that, unfortunately it still stops after finding the first email address.
you need an extra line when setting the regex options
i tested it will then return all matches, instead of just the firstregex.Global = True
AWESOME AWESOME AWESOME, That works.
Thank you sooooooo much for your help.
Oh dear it has a problem, if there is more that one email in the folder then it doesn't extract any email addresses, but if there is only one email in the folder then it extracts all the email addresses correctly.
you need to use the original code posted before, with just the small part i changed in place of the original
make sure to use the correct folder path
check the array is still correct immediately after redim preserve
post your entire code, as i do not see any reason, in any of the codes posted, why such a problem should be occurring
there are probably some errors in the suggested code, but they would cause errors to occur, not just wrong results, unless some inappropriate error handling
It wont let me post the full code, says post denied.
It runs through fine with one email in the selected folder, if I put more than one email into the folder it comes up with an error:
Run-time Error 440 - Array index out of bounds - and highlights this line: "strBody = olFolder.Items(i).Body" when I say debug.
thank you so much for you help.
that line should be
it would appear i must have copied and pasted code from post #5 as the code in all other posts seem to have it correctstrBody = Item.Body
ok that worked, now there is another error, i have attached a screenshot.
Outlook VB.jpg
try changing to
on line 3redim badaddresses(0)
Dear , I am using this code and run perfectly but emails not showing in excel sheet.