+ Reply to Thread
Results 1 to 8 of 8

VBA is exiting the procedure instead of running the rest of the code

  1. #1
    Registered User
    Join Date
    11-13-2015
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Angry VBA is exiting the procedure instead of running the rest of the code

    Hi All,

    I'm working on an automated email system for our company's design tracker. Essentially, at the end of each day, emails go out to the designated customer providing them with an update on the status of their design.

    Everything has worked in previous versions, but I'm adding in a new checking process. My boss doesn't want the customers to receive the same emails "x" amount of times in a row, so I've established a counting system. The problem comes up like so:

    1) The loop initiates
    2) Assuming the client has opted in for email updates, has provided a valid email address, and has an incomplete design in the system, an email template is selected. (I've only included one for reference, as the only difference between them is the wording of the email).
    3) The appropriate template procedure is then run, checking for the quantity of previous emails sent under this format. If the quantity of emails sent is less than the cap, it increases the "emails sent count" by one, and SHOULD assign the email body template and then return to the "SelectTemplate" procedure that called it.

    Instead of that, the macro is exiting the procedure after it increases the "emails sent" count and returning to the "ProcessData" procedure and finishing the loop, skipping over the code that sends the email.

    Please Login or Register  to view this content.
    ------------------------------------------------------------------

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA is exiting the procedure instead of running the rest of the code

    Hi Jesse,

    I've had routines ignore called subroutines when the code doesn't put "Call" before the Sub Name (even when there were no arguments) - you could try that
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

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

    Re: VBA is exiting the procedure instead of running the rest of the code

    Have you stepped through the code using F8?

    PS Just having a quick look over the code there seems to be a lot of unqualified range references.
    Last edited by Norie; 11-13-2015 at 08:48 PM.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    11-13-2015
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA is exiting the procedure instead of running the rest of the code

    xladept, thanks! I tried that solution, but it has not worked.

    Thanks Norie. I have tried stepping through the code, and that's how I came to find the issue with procedures being skipped over.

    If we go to the SelectTemplate Procedure, and pretend that "BEING CHECKED" is the case, this is what happens when I step through the code:

    intBCES is assigned a new value
    BCTemplate is called
    intBCES <> 2
    The cell that stores the value of intBCES is increased by one
    The code jumps back to the process data loop instead of: 1) creating strEmailBody 2) returning to the SelectTemplate procedure and 3) completing the rest of SelectTemplate, which includes the sub to send out the email.

    I tried attaching the file, but it's too large. If you'd like to see the file, I have it in my google drive: https://drive.google.com/file/d/0B3g...ew?usp=sharing

    Again, thank you all for your help!

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: VBA is exiting the procedure instead of running the rest of the code

    What happens if you turn off error handling?

  6. #6
    Registered User
    Join Date
    11-13-2015
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA is exiting the procedure instead of running the rest of the code

    I get the same results.

    When I comment out the lines that increase the count of each specific email sent, the macro executes perfectly.


  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA is exiting the procedure instead of running the rest of the code

    Hi Jesse,

    Thanks for the rep!

    Is IntBCES>2??

  8. #8
    Registered User
    Join Date
    11-13-2015
    Location
    Denver, Colorado
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA is exiting the procedure instead of running the rest of the code

    intBCES and the rest of the ES counts are currently at zero.

+ 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. Input box stops rest of code running
    By Phoebus in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2014, 10:36 AM
  2. Code Procedure Problem: Exiting Select Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2010, 12:21 AM
  3. Excel running in background after exiting from mail merge
    By Dynamo Nath in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-20-2009, 11:07 AM
  4. Interrupting Procedure Without Exiting?
    By Timmy Mac1 in forum Excel General
    Replies: 6
    Last Post: 12-22-2006, 09:43 AM
  5. Run a procedure when exiting a a textbox within a userform
    By borg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2006, 02:10 AM
  6. question about exiting a procedure
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-05-2006, 04:25 AM
  7. Exiting a procedure with a userform
    By jumpjump in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2005, 04:05 AM

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