+ Reply to Thread
Results 1 to 4 of 4

VBA Script to send email works 1st time, fails 2nd time

  1. #1
    Registered User
    Join Date
    01-21-2020
    Location
    New Mexico
    MS-Off Ver
    Office 2016
    Posts
    4

    VBA Script to send email works 1st time, fails 2nd time

    Hi all, I use the script below in a form for my users. I am getting an error failing at the With Selection.Parent.MailEnvelope.Item step if the user runs the macro a 2nd time (works fine on the 1st attempt). If the user closes the file and reopens, it works fine again. Any ideas on where I went wrong here?

    Please Login or Register  to view this content.
    Last edited by AliGW; 05-11-2020 at 08:05 AM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,607

    Re: VBA Script to send email works 1st time, fails 2nd time

    All these are not "perfect" solutions. Rather protheses. But work :-)

    If you can afford saving the workbook - save it after the code is called. There shall be no problem with second attempt.
    If not - before mailing make a copy of current workbook, mail what is needed and destroy. For instance like this:
    Please Login or Register  to view this content.


    Administrative Note:

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    01-21-2020
    Location
    New Mexico
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: VBA Script to send email works 1st time, fails 2nd time

    Thank you, unfortunately this won't work for me as the emails are now being blocked from being sent by our corp email rules.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,383

    Re: VBA Script to send email works 1st time, fails 2nd time

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new, I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Send Specified sheet range as email on specified date and time
    By diddy47 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-03-2020, 07:16 AM
  2. Replies: 3
    Last Post: 08-27-2015, 02:38 PM
  3. Send email at specific time
    By platesigns in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2014, 01:48 PM
  4. Macro to email as PDF only works when run for a second time.
    By CBeardmore in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2014, 03:45 PM
  5. Send Email on a specific date and time using Excel Only.
    By j_panky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2013, 12:09 PM
  6. How to send email at specified time?
    By batman07 in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 06-30-2011, 01:24 PM
  7. Keep time format during send email
    By eriknokc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2009, 08:27 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