Note that there are some explanatory texts on larger screens.

plurals
  1. POAllow user to kill process during wait in VBA
    primarykey
    data
    text
    <p>I have written a program to print multiple <code>.pdf</code>s with varying file extensions off of an Excel spreadsheet list.<br> The problem is that it takes anywhere from 30 seconds to a minute for the printer to receive the pdf after the line: <code>Application.SendKeys "^p~", False</code> is called.<br> To get by this I used <code>Application.Wait (Now + TimeValue("0:01:03"))</code> to wait for a minute (plus 3 seconds just to be safe) before closing the file. To me there seems like there should be a better way than just causing the program to wait, so I looked around a little and <a href="https://stackoverflow.com/questions/16073972/doevents-waiting-and-editing">found a question about this lovely gem</a> known as <code>Application.OnTime</code>.</p> <p>I tried a sample of <a href="https://stackoverflow.com/a/16074309/1393894">one of the answers</a>:</p> <pre><code>Sub test2() ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(1, 1).Value + 1 Application.OnTime Now + TimeValue("00:00:5"), "test2" End Sub </code></pre> <p>However when I tried to stop the above code it kept going on an infinite loop and I was unable to stop it until I killed excel using the windows task manager.</p> <p>I would like to be able to add in a little message box or something of the sort so that the user can click in between the wait time.<br> So that while the program is waiting for a minute, the user can either manually click and start the program on the next pdf, or click another button to exit if they need to stop printing early. Something like this:</p> <pre><code>Sub pdfPrinter() '... 'Insert all the other code here '... Application.SendKeys "^p~", False Application.OnTime Now + TimeValue("00:01:02"), "pdfPrinter" continue= MsgBox("Click Retry to print again, or cancel to stop printer.", vbRetryCancel) If continue = vbRetry Then Call pdfPrinter ElseIf continue = vbCancel Then Exit Sub End If End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload