+ Reply to Thread
Results 1 to 6 of 6

Halt Printing

  1. #1
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Halt Printing

    I am printing a lot of data from an excel spreadsheet using a vba macro print loop for printing many forms. I want to allow the user to cancel printing in the middle of the job but can't find a way to accept the user's clicking on a cancel button. I have tried DoEvents but this seems to just be ignored by VBA. Is there any way to let the user interact with code running in a vba macro?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Halt Printing

    You could put up a modeless userform with a Cancel button that clears a public variable that is checked by the print code in each iteration.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Re: Halt Printing

    Tried that but the cancel click event code is not executed to clear the public variable until the print macro is finished even though I have DoEvents in the macro. Also tried running from a modal form with same result..the events are not executed until the macro is done.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Halt Printing

    Tried that but the cancel click event code is not executed to clear the public variable until the print macro is finished
    Can't imagine why it shouldn't. It's always worked for me.

    Also tried running from a modal form with same result.
    With a modal form, code suspends (other than form events) until the form is closed -- that's why you need a modeless form.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Halt Printing

    It looks like you have two issues:
    a. Stopping the Macro - which shg has addressed.
    b. Clearing jobs from the Print Spooler. You may be able to do this as follows (if you have Administrator privileges):
    (1) Install file 'ClearPrintQueue.bat' in the same folder as your Excel File.
    (2) Run Macro SpawnClearPrintQueueDotBatFileAsAdministrator() from your Excel file.

    Unfortunately with today's fast printers with lots of memory, the printer itself may have control of the printing process.


    Contents of file 'ClearPrintQueue.bat':
    Please Login or Register  to view this content.

    Run Macro SpawnClearPrintQueueDotBatFileAsAdministrator() to clear the Print Queue. Windows will ask you if you want to Continue:
    Please Login or Register  to view this content.

    NOTE: Not allowed to upload .bat file - If you download attached file, change the file name to 'ClearPrintQueue.bat'.


    Lewis
    Attached Files Attached Files
    Last edited by LJMetzger; 12-06-2017 at 03:34 PM.

  6. #6
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Re: Halt Printing

    Thanks...I'll give it a try. My printing is actually done to a word document which is then printed. If I can get user events to be recognized during the generation of the word document (this takes a couple of minutes to generate), then the user can stop the word document and I wouldn't send to the printer.

+ 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] FORMULAS bringing Excel to a halt - need advice
    By PWM in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-24-2014, 06:01 PM
  2. [SOLVED] Keep Macro From Screeching To A Halt
    By amartin575 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-23-2013, 04:11 PM
  3. [SOLVED] Halt running macro when cell changes?
    By Rhudi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-16-2013, 02:13 PM
  4. How do I HALT all VBA running code w/ 1 instruction
    By sauerj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-12-2010, 09:09 AM
  5. [SOLVED] Halt or Pause a Macro
    By Tomkat743 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-21-2006, 02:25 PM
  6. [SOLVED] Halt A Macro If a Cell Contains a Certain Value
    By John in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-28-2005, 04:05 PM
  7. Halt all code while macro runs
    By TimT in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2005, 12:05 PM
  8. [SOLVED] [SOLVED] Halt recalculation
    By ojv in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-19-2005, 08:06 PM

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