+ Reply to Thread
Results 1 to 9 of 9

Looping Email- Multiple Attachments but I Only Want Selected Attachment

  1. #1
    Registered User
    Join Date
    04-27-2012
    Location
    New York, USA
    MS-Off Ver
    Excel 2010
    Posts
    63

    Looping Email- Multiple Attachments but I Only Want Selected Attachment

    Hopefully someone will be able to help me figure this one out. I have done some research, and so far no luck.

    I have a function that loops through my spreadsheet and checks the due date for an invoice and whether or not it has been approved and sends out a reminder email to the approver with the invoice as an attachment.

    The first email sent works great, the second attaches the first invoice and the newly selected invoice, the third email attaches the first 2 and the selected one, and so on.

    Does anyone know of a way to clear out attachments after the mail is sent so only the selection attaches to the next email? I appreciate any help I can get!

    Here's my coding:

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    Hello cschoyer,

    The Attachments is a Collection object which is part of the Message object. I have added the line to clear all the attachments after the email is sent. The added line is in bold.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    04-27-2012
    Location
    New York, USA
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    When I run this excel stops working and I get a window that says "Microsoft Excel has stopped working - Windows can check online for a solution to the problem and try to recover your information."

    ...?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    Hello cschoyer ,

    I am not sure why you are getting that message. The code line added is part of the standard Windows CDO library of functions and should not cause Excel to crash. Perhaps it has to do with the timing of sending the attachment before it is deleted. Let's move the the delete statement to the beginning and see it that works.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-27-2012
    Location
    New York, USA
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    Hm, even with the delete all at the beginning, it still causes excel to crash.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    Hello cschoyer,

    Are any of the emails being sent or does it crash on the first email?

  7. #7
    Registered User
    Join Date
    04-27-2012
    Location
    New York, USA
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    it crashes on the first email

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    Hello cschoyer ,

    After looking over your macro, I found a few problems. Since this obviously only part of the code, these may not be problems but simply variables that set elsewhere.

    1. Mail_Server this not set anywhere in the macro. It should be set to name of the mail server you are using, like "www.google.com".
    2. Your port is set to 25 which is fine if the server does not require you to log in.
    3. iConf was incorrectly assigned as CDO.Configuration when it should have been CDO.Message.Configuration.

    Make the needed corrections to 1 and 2 in the code below. Once you have, try running it again.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-27-2012
    Location
    New York, USA
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Looping Email- Multiple Attachments but I Only Want Selected Attachment

    Your right, this is only part of my code so issues 1 and 2 are taken care of elsewhere.

    Thanks for picking up on error 3- this code works brilliantly, exactly as I wanted it to. Thank you so much for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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