+ Reply to Thread
Results 1 to 8 of 8

Saving an Outlook Attachment then move to another folder.

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Saving an Outlook Attachment then move to another folder.

    Although this code is run from Excel, I presume this is an Outlook issue.

    I want to go though all the messages in a specific folder, save the attachment and then move the message to a sub folder. The following code reads the messages in the folder. That's as far as I can get.

    The first failure is on this line:
    Please Login or Register  to view this content.
    I get the error "The attempted operation failed. An object could not be found." The line above it works. I have confirmed that the SubFolder does exist.

    OK,so we comment that out and let's try to save the attachment.
    Please Login or Register  to view this content.
    Both of these incantations fail with "Object variable with block variable not set." It knows the Excelfolder (again confirmed that it does exist) but doesn't like Filename or Displayname.

    And of course, I can't even get to
    Please Login or Register  to view this content.
    until I get the other problems fixed.

    Here's the full code - it works only because I have the parts I want to do commented out.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Saving an Outlook Attachment then move to another folder.

    Try something like...
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Saving an Outlook Attachment then move to another folder.

    As for failure on below line...
    Please Login or Register  to view this content.
    Mailbox should be the email account, then each subsequent subfolders. Tested on my Outlook and works fine as long as I follow folder structure.
    Used following for test.
    \[email protected]\Inbox\DailySales\Test

    Stuck in there one mail from yesterday. And used the loop code posted above to save attachment on the email to my local drive.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Saving an Outlook Attachment then move to another folder.

    Thanks. That solves one of my problems. Now I have an issue with identifying the sub folder. Sometimes I get the error, sometimes I don't. Opening and closing outlook seems to have some sort of an effect on whether it works. When the error doesn't happen, it will loop though about half the messages in the folder and stop. I can re-execute it and it will do half of the remainder and so on until only one item is left and then it executes it. That's why I threw in the DoEvents.

    Here is the code as it exists now.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Saving an Outlook Attachment then move to another folder.

    P.S. I closed outlook and re-opened it so I did not get the error and I stepped through the code manually. I had 7 messages in the folder. It processed 4 of them, and then moved out of the Next olMail loop with three messages still left in the box. I ran the code again on the remaining three messages and it processed two of them leaving one. I though I knew how to do loops?

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Saving an Outlook Attachment then move to another folder.

    Try replacing for each loop for mail item with For i = loop.

    Something like...
    Please Login or Register  to view this content.
    My best guess is that by using .Move index for each mail got moved up 1 and hence reached end of folder items faster than anticipated (by skipping some items).

    Edit: Using same concept as when you are looping through rows in cell range and deleting rows.
    Last edited by CK76; 10-30-2017 at 12:46 PM. Reason: See edit:

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Saving an Outlook Attachment then move to another folder.

    Not only does that make sense, it works . Obviously, I don't work with Outlook a lot. So this is analogous to removing rows from a sheet in Excel and is not analogous to looping through files in a windows folder.

    Thanks for all your help. Now I'll attend to that pesky intermittent error message.

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Saving an Outlook Attachment then move to another folder.

    You are welcome and thanks for the rep

+ 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. How to prevent VBA Code from saving same outlook attachment again ?
    By avis_1989 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2016, 12:31 PM
  2. Saving File Attachment from Outlook to Network Drive
    By TRMoonPunk in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 10-30-2014, 02:36 PM
  3. Save an Outlook attachment and move the email to a folder based and sender
    By db16886 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 09:49 PM
  4. Dowload outlook email attachment to my pc folder using Excel VBA
    By din.malay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2013, 08:06 AM
  5. Dowload outlook email attachment to my pc folder
    By din.malay in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 12-11-2013, 03:34 AM
  6. Saving Attachment from Outlook to a specified location on my computer
    By dwhite30518 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2012, 10:32 AM
  7. [SOLVED] Outlook attachment to network folder
    By Ozzie via OfficeKB.com in forum Excel General
    Replies: 2
    Last Post: 02-03-2006, 07:20 AM

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