Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 34 of 34

Thread: Solved: Parse email body for email addresses and write them to Excel...Help with Troubleshoot

  1. #21
    VBAX Regular
    Joined
    Nov 2014
    Posts
    7
    Location
    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.

  2. #22
    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

  3. #23
    VBAX Regular
    Joined
    Nov 2014
    Posts
    7
    Location
    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.

  4. #24
    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

  5. #25
    VBAX Regular
    Joined
    Nov 2014
    Posts
    7
    Location
    Hi westconn1, thank you for that, unfortunately it still stops after finding the first email address.

  6. #26
    you need an extra line when setting the regex options

    regex.Global = True
    i tested it will then return all matches, instead of just the first

  7. #27
    VBAX Regular
    Joined
    Nov 2014
    Posts
    7
    Location
    AWESOME AWESOME AWESOME, That works.
    Thank you sooooooo much for your help.

  8. #28
    VBAX Regular
    Joined
    Nov 2014
    Posts
    7
    Location
    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.

  9. #29
    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

  10. #30
    VBAX Regular
    Joined
    Nov 2014
    Posts
    7
    Location
    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.

  11. #31
    that line should be
    strBody = Item.Body
    it would appear i must have copied and pasted code from post #5 as the code in all other posts seem to have it correct

  12. #32
    VBAX Regular
    Joined
    Nov 2014
    Posts
    7
    Location
    ok that worked, now there is another error, i have attached a screenshot.

    Outlook VB.jpg

  13. #33
    try changing to
    redim badaddresses(0)
    on line 3

  14. #34
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    1
    Location
    Dear , I am using this code and run perfectly but emails not showing in excel sheet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •