+ Reply to Thread
Results 1 to 6 of 6

Exit a Macro if Canceled

  1. #1
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Exit a Macro if Canceled

    Greetings,
    Not sure as to why my previous thread did not post. I have several macros to either Save or Print (PDF) a worksheet. I would like to insert code to cancel/exit the macro if the user presses the "Cancel" button on the SaveAs or Print dialog box (the computer standard dialog box). Here is a sample code:

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Exit a Macro if Canceled

    No me neither. I've never seen that 'Printable' View on the forum before. I'll close your earlier thread.

    I'd be inclined to put your macro in the Workbook BeforeSave event procedure. That has a built in Cancel perimeter you can use to capture the situation where someone cancels. Similarly in the BeforePrint procedure.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Exit a Macro if Canceled

    Quote Originally Posted by Richard Buttrey View Post
    No me neither. I've never seen that 'Printable' View on the forum before.
    It automatically happens if the thread title ends in print.
    If you change the last word of the title, it should correct itself.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Exit a Macro if Canceled

    Thanks Fluff. That's a new one for me in my 11 years here but useful to know for the future.

    I'd already deleted the original so I'll leave it on this occasion.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Exit a Macro if Canceled

    Try
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Re: Exit a Macro if Canceled

    mike,
    Works perfect!
    Thank you much!

+ 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. [SOLVED] Runtime Error 91 when Macro canceled
    By LKERN in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2018, 06:49 PM
  2. BeforeClose only works once; if Canceled will not work again
    By noizewarr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2016, 02:49 AM
  3. [SOLVED] Delete worksheet if inputbox is canceled
    By JujuS in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-27-2015, 03:43 PM
  4. canceled and restore arrows are grayed out in Excel with this macro
    By gibtoul in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-31-2013, 11:32 AM
  5. average duration for canceled bills
    By kghisla in forum Excel General
    Replies: 3
    Last Post: 12-04-2010, 08:28 PM
  6. Workbook_BeforeClose event is not canceled
    By Mircea Pleteriu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2005, 11:05 AM
  7. WorkbookBeforeClose event is not canceled
    By Mircea Pleteriu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2005, 12:05 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