+ Reply to Thread
Results 1 to 4 of 4

For Each Loop keep given me an error

  1. #1
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    For Each Loop keep given me an error

    This is just a portion of my codes. Basically, this For Loop is supposed to loop through all the attachments of an outlook mail item. If the mail item has one attachment, it would loop through and save that mail item to the correct folder, but then for some reason it loops through again trying to read the second attachment when there is only one attachment. Why does this code do that? How come it did not stop because the mail item only has one attachment? It gives me an error because it couldn't find a second attachment.
    Last edited by alexduy; 04-15-2021 at 05:40 PM.

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: For Each Loop keep given me an error

    I admit I don't do much Outlook scripting. For the heck of it, what does Debug.Print olMail.Attachments.Count produce in the Immediate Window? If it produces 1, then an alternative rather than an explanation,

    Please Login or Register  to view this content.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: For Each Loop keep given me an error

    I can immediately see at least one possible problem in the code, olMail is an Outlook VBA constant and not a good name for a variable in Outlook VBA.

    I think we need to see the rest of the code.
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    Re: For Each Loop keep given me an error

    I've added the full code

+ 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] Excel VBA - Loop through recordsets ADODB with For Loop Error - Help
    By ironfelix717 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-27-2018, 08:44 AM
  2. Replies: 5
    Last Post: 12-08-2016, 06:43 PM
  3. [SOLVED] Go to next loop iteration if current loop has error
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-03-2016, 09:54 PM
  4. Loop Nesting is returning Run-Time Error '-2147221080 (800401a8)': Automation Error
    By ChristopherBrandonKi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2014, 02:36 PM
  5. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  6. Nesting a loop within a loop error
    By PunPryde in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2011, 08:07 PM
  7. Error '1004', application/object error, Do Loop
    By farzyness in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2011, 12:03 PM

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