+ Reply to Thread
Results 1 to 11 of 11

Pulling info from Outlook using VBA

  1. #1
    Registered User
    Join Date
    08-17-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    6

    Pulling info from Outlook using VBA

    I found the below script on another site, but it does not work for certain MailItems (such as SenderName, SenderEmailAddress, and Body). However, ReceivedTime and Subject work fine.

    With "SenderName" and "SenderEmailAddress" I get this error:

    Run-time error '?2147467259 (80004005)':
    Method 'SenderName' of object '_Mailltem' failed

    With Body I get this error:

    Run-time error '287':
    Application-defined or object-defined error

    I am brand new to using visual basic so any help would be appreciated. Thanks.


    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Our guidelines recommend code tags. I have added them for you this time because you are a new member. Also consider indentation to show structure. --6StringJazzer
    Last edited by 6StringJazzer; 08-18-2023 at 12:36 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Pulling info from Outlook using VBA

    Welcome to the Forum Excel3257705!

    You said it does not work for "certain" email items. What can you tell us about the particular emails that it does not work for? I will see if I can run this code and see what's happening.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Pulling info from Outlook using VBA

    I am getting a "type mismatch" runtime error when I encounter a meeting notice, because it is in the Items collection but is not a MailItem object. But that is not the same error you are getting.

    I will look into how to resolve this but it may not fix your problem.

  4. #4
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Pulling info from Outlook using VBA

    Hi, try this

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-17-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    6

    Re: Pulling info from Outlook using VBA

    Thanks for your reply. My reference to "certain" MailItems was intended to mean properties of Outlook not particular e-mails. For instance if the below code is used, it works fine. Also, I am choosing a folder which only has e-mails in it (it doesn't have any meeting notices, etc.)

    Please Login or Register  to view this content.
    But if the lines with "SenderName, SenderEmailAddress, and Body" are added back in, I get the errors referenced in my previous post.

    Also, the below code doesn't work either and contains a specific reference to mail items (the line with "If objItem.Class = olMail"), so I don't think the class of the item is the issue.



    Please Login or Register  to view this content.
    Thanks again for your assistance.

  6. #6
    Registered User
    Join Date
    08-17-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    6

    Re: Pulling info from Outlook using VBA

    Quote Originally Posted by JEC. View Post
    Hi, try this

    Please Login or Register  to view this content.
    Thanks for your reply. I get the same errors as before with your code. Also like before, if I take out the line with SenderName, SenderEmailAddress, and Body, then it works fine.

  7. #7
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Pulling info from Outlook using VBA

    What if you only comment out the body? Is it giving the error with the first item already?
    Last edited by JEC.; 08-18-2023 at 01:33 PM.

  8. #8
    Registered User
    Join Date
    08-17-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    6

    Re: Pulling info from Outlook using VBA

    Quote Originally Posted by JEC. View Post
    What if you only comment out the body? Is it giving the error with the first item already?
    Same error:

    Run-time error '-2147467259 (80004005)':
    Method 'SenderName' of object '_Mailltem' failed

    I found a post on another forum re: a similar issue which contained the following:

    "I had a similar problem, and it bugged the heck out of me. My eventual fix (workaround) was using a variable, which you wouldn't think would matter. Declare a string variable and then populate and use it."

    Unfortunately, I don't know enough to use the fix described above.

    Thanks.

  9. #9
    Registered User
    Join Date
    08-17-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    6

    Re: Pulling info from Outlook using VBA

    Quote Originally Posted by Excel3257705 View Post
    Same error:

    Run-time error '-2147467259 (80004005)':
    Method 'SenderName' of object '_Mailltem' failed

    I found a post on another forum re: a similar issue which contained the following:

    "I had a similar problem, and it bugged the heck out of me. My eventual fix (workaround) was using a variable, which you wouldn't think would matter. Declare a string variable and then populate and use it."

    Unfortunately, I don't know enough to use the fix described above.

    Thanks.
    The post described above stating using string variables was the solution in a similar instance is #57490 from accessforums dot net

  10. #10
    Registered User
    Join Date
    08-17-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    6

    Re: Pulling info from Outlook using VBA

    This morning I posted this same question to the Experts Exchange website. If I receive an answer I will post it here. Thanks.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Pulling info from Outlook using VBA

    Please post a link to your thread on Experts Exchange. It's fine to post elsewhere but our rules require a link when you do.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Pulling info from one sheet to another
    By melymelmela in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-17-2019, 10:47 PM
  2. VBA for pulling out info on changes
    By areskoug in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-10-2017, 03:33 AM
  3. [SOLVED] Pulling info from other sheets
    By Judylily in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-20-2017, 04:27 PM
  4. Need help pulling info from a list
    By andyaf in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2013, 05:05 PM
  5. Pulling info from one sheet to another
    By floridavera in forum Excel General
    Replies: 6
    Last Post: 05-20-2011, 08:46 AM
  6. Pulling info from worksheet
    By jcarstens in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2009, 02:41 PM
  7. Pulling info into another sheet
    By Teric506 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-26-2005, 01:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1