+ Reply to Thread
Results 1 to 12 of 12

Bug in code sending email

  1. #1
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Bug in code sending email

    I Give
    I run this macro and all run perfect if there is a address in the address book,but if no address in the address book a inputbox comes up and you can enter the email address and click ok and the code works perfect. But when you click cancel it does exit the sub but it kills all the working work sheet events. In worksheet two day it has a calendar popup when you click a certain cell it opens a calendar,this quits working when you click cancel on the inputbox.? There is some conditional formatting on the worksheet that quits too. When I click cancel this stuff all quits,but if I go back and try and send email that is not in address book and the inputbox comes up and I enter a email it all starts working again. Its like when you cancel the inputbox it exits the sub but something in hung up in the workbook.?? If I close and save the workbook and reopen all is well,got to be something with inputbox cancel not releasing something?
    Thanks for any ideas,after two days I give.






    Please Login or Register  to view this content.
    Last edited by zplugger; 01-24-2017 at 11:10 AM.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Bug in code sending email

    The code is doing exactly what you tell it to do 'Cancel'

    You will have to tell it to do what you want or add an extra promt like process next one Yes / No
    And BTW, you should Dim all your variables there are a series you forgot to Dimension
    like vBody and some more.
    Happy coding.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Bug in code sending email

    Thanks Keebellah for the info,I got this code from another forum member. A lot of this is well over my head,seems like when I click cancel it should all go back to where I started? Not sure
    why all the other stuff quits working on the worksheet.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Bug in code sending email

    This section of code:

    Please Login or Register  to view this content.
    if you hit cancel vEmailAddress is false, so the code should give you a message that no email will be sent, quit outlook, and then exit the code (Exit Sub).
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Bug in code sending email

    That's what you get when you want to be a carpenter but don't know how to hold the hammer:

    Please Login or Register  to view this content.
    Wher it says Exit Sub, thas is eaxctly what it does.
    So here you will have to add the wuestion if you want to continue or not and my guess is that that's a little over your head

    That section has to be modified but I'm not going into it because they approached it a different way I would do it, but here's the main idea:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Bug in code sending email

    I typed it in dit not check all the syntax but it's just to give you the idea of what would be required

  7. #7
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Bug in code sending email

    Thank You I will give it a try LOL

  8. #8
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Bug in code sending email

    Thanks Arkadi
    if you hit cancel vEmailAddress is false, so the code should give you a message that no email will be sent, quit outlook, and then exit the code (Exit Sub). It does do this, but if I cancel it takes some of the functions away from sheet two day. Functions will return if I send a email,just lost why I would loose functions on cancel.

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Bug in code sending email

    The reason is that there is no code to make it do something else and there is also no code to check if the email address entered is a valid email address as goes for syntax, that is another issue you might run into.
    Coding with VBA is simple but you can to tell it EVERYTHING and does exactly what you tell it to do, no more, no less, Syntax errors generate errors, etc. etc.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Bug in code sending email

    You mean some events (like worksheet change) stop working? becuase EnableEvents has been disabled earlier in the code, and the early "Exit Sub" means it never reaches the end of the code where it is re-enabled.
    Quickest way to fix that is to put this:
    Please Login or Register  to view this content.
    between
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    The tidy way would be to replace the exit sub with a goto command, where the goto location is at the end of the code where you re-instate enableevents and screenupdating.

  11. #11
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Bug in code sending email

    Out Standing Arkadi, that did the trick. I tried tat earlier but not in that exact place.

    Thank You

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Bug in code sending email

    Glad we could help you solve the issue
    I appreciate the rep, and thanks very much for remembering to mark the thread as solved

+ 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. Change VBA to allow email code to bring up outlook email before sending it
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2015, 02:33 AM
  2. [SOLVED] Why is my email code sending a blank email?
    By gmr4evr1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-28-2015, 10:20 AM
  3. Sending a code to an email through excel
    By levitt in forum Excel General
    Replies: 1
    Last Post: 11-24-2014, 08:21 PM
  4. Help with sending email using VBA code
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2014, 05:16 AM
  5. [SOLVED] Code is sending same chart to all email body .
    By Sushil.thakur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2013, 02:35 AM
  6. [SOLVED] VB Code to save an email to hdd on sending
    By cnixon in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 08-03-2012, 04:33 AM
  7. Using code to email a sheet but need to strip the code before sending
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-05-2009, 01:44 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