MS Office Forum / Word / Programming / July 2005
Abort printing
|
|
Thread rating:  |
RB Smissaert - 16 Jul 2005 00:37 GMT Is there any way in VB to abort a print job that is in progress? I am talking here about the situation where paper is coming out of the printer. I had a good search for this, but nil found sofar. Thanks for any advice.
RBS
Karl E. Peterson - 16 Jul 2005 00:49 GMT > Is there any way in VB to abort a print job that is in progress? > I am talking here about the situation where paper is coming out of the > printer. Usually, by that point, the entire job has traversed the wire to the printer, and is beyond Windows' control. Only thing I've found that works, by then, is yanking the power cord.
 Signature Working Without a .NET? http://classicvb.org/petition
RB Smissaert - 16 Jul 2005 01:03 GMT But you can stop it via control panel (I think I did once), so why can't this be done in VB?
RBS
>> Is there any way in VB to abort a print job that is in progress? >> I am talking here about the situation where paper is coming out of the [quoted text clipped - 5 lines] > yanking the > power cord. Karl E. Peterson - 16 Jul 2005 01:56 GMT > But you can stop it via control panel (I think I did once), so why > can't this be done in VB? Well, yeah, you can always *try* to pull an Abort on it, sure. But as I said, if the pages are already spitting, the odds are that most/all of the bits have already spooled. To get an idea of how to send an Abort, see http://vb.mvps.org/samples/PrnInfo -- in particular, the following methods of the CPrinterJobs class:
Public Function ControlCancel(ByVal JobId As Long) As Boolean Dim os As OSVERSIONINFO ' NT4 is the dividing line between two different ' control codes for this call. os.dwOSVersionInfoSize = Len(os) Call GetVersionEx(os) ' Attempt to cancel passed job. If os.dwPlatformId = VER_PLATFORM_WIN32_NT And os.dwMajorVersion >= 4 Then ControlCancel = SendControl(JobId, jcDelete) Else ControlCancel = SendControl(JobId, jcCancel) End If End Function
Private Function SendControl(ByVal JobId As Long, ByVal ControlCode As JobControlCodes) As Boolean Dim hPrn As Long ' Get handle to printer. Call OpenPrinter(m_DevName, hPrn, ByVal 0&) If hPrn Then ' Send requested control code. SendControl = CBool(SetJob(hPrn, JobId, 0, ByVal 0&, ControlCode)) Call ClosePrinter(hPrn) ' Update all object data. Call Me.Refresh End If End Function
That will, at least, stop Windows from sending any more bits down the wire. What's already in the printer's internal buffer is out of reach, however.
Good luck... Karl
 Signature Working Without a .NET? http://classicvb.org/petition
RB Smissaert - 16 Jul 2005 06:11 GMT OK, thanks, I can see that I need a different approach. I n my particular case I am printing lots of small documents from Excel with OLE automation to Word like this:
Dim wd As Word.Application Set wd = New Word.Application
Go = 3
For i = 1 To UBound(arrFiles) DoEvents If Go = 1 Then Exit For End If wd.Documents.Open FileName:=strPath & "\" & arrFiles(i), ReadOnly:=True wd.ActiveDocument.PrintOut Background:=False wd.ActiveDocument.Close wdDoNotSaveChanges ShowProgressMessage " " & _ Round(100 * (i / UBound(arrFiles)), 0) & _ " % done" Next
What I need here is either a notification event from the printer that another document is done and only then go to the next element of the array of documents. Not sure this can be done. Or the other way is just to ask the user: how many seconds do you want to wait in between the documents? The wait period may then have to be a loop with DoEvents to get the keyboard press (spacebar) that sets the variable Go to 1. Any further suggestions?
RBS
>> But you can stop it via control panel (I think I did once), so why >> can't this be done in VB? [quoted text clipped - 42 lines] > > Good luck... Karl Karl E. Peterson - 18 Jul 2005 20:22 GMT > What I need here is either a notification event from the printer that > another document is done and only then > go to the next element of the array of documents. Not sure this can > be done. You could monitor the printer for a "Ready" status.
 Signature Working Without a .NET? http://classicvb.org/petition
RB Smissaert - 19 Jul 2005 14:23 GMT Thanks, will try that. I now have just asked the user how long printing one page roughly takes and pause the loop for this time. Monitoring the printer will be much slicker.
RBS
>> What I need here is either a notification event from the printer that >> another document is done and only then >> go to the next element of the array of documents. Not sure this can >> be done. > > You could monitor the printer for a "Ready" status. MikeD - 16 Jul 2005 04:18 GMT Even via Control Panel or the Printer dialog (double-clicking the print icon in the systray, and these might even be one-in-the-same), you can only abort what hasn't already been fed to the printer. If you're printing a large document, it might be entirely spooled, but Windows is feeding it to the printer in the background. At what point you can abort printing, if you can at all, depends on the printer itself (i.e. how much memory it has).
As far as VB, it only lets you abort if you're still spooling (i.e., there's been no Printer.EndDoc). You might be able to use the AbortPrinter Win32API function to abort a print job that you've "completed" in VB (IOW, you've executed Printer.EndDoc), but even then, only what *hasn't* been sent to the printer already would get aborted. Also, this would depend on whether spooling and background printing is enabled (and possibly even other printer settings supported by any given printer).
 Signature Mike Microsoft MVP Visual Basic
> But you can stop it via control panel (I think I did once), so why can't > this be done in VB? [quoted text clipped - 10 lines] >> yanking the >> power cord. Anne Troy - 16 Jul 2005 01:07 GMT Interesting, Karl. I'm going to have the classicvb petition posted as an announcement at www.vbaexpress.com. I suspect you'll get a good amount of new signers from it.
:) ******************* ~Anne Troy
www.OfficeArticles.com
> > Is there any way in VB to abort a print job that is in progress? > > I am talking here about the situation where paper is coming out of the [quoted text clipped - 3 lines] > beyond Windows' control. Only thing I've found that works, by then, is yanking the > power cord. Karl E. Peterson - 16 Jul 2005 02:02 GMT Hi Anne --
Hey, that'd be great! If you'd also like to display banner(s), take a look at http://classicvb.org/#Banners (others are also available, if none of those work!)
Btw, we had some "server issues" with signatures last week. If you hear of anyone that says they tried but were rejected, please urge them to take another shot at it. I'm fairly certain the problem was resolved.
Thanks... Karl
 Signature Working Without a .NET? http://classicvb.org/petition
> Interesting, Karl. I'm going to have the classicvb petition posted as > an announcement at www.vbaexpress.com. I suspect you'll get a good [quoted text clipped - 17 lines] >> Working Without a .NET? >> http://classicvb.org/petition Anne Troy - 16 Jul 2005 06:04 GMT Okay, I've got one here: http://www.officearticles.com/ And I also have about 30,000 posts around the internet on forums, which will all update when I change my signature. For any that let me, I'm going to put the banner, tho I may be stuck using the vBulletin code and not the HTML. :) Let's see what I can do. ******************* ~Anne Troy
www.OfficeArticles.com
> Hi Anne -- > [quoted text clipped - 27 lines] > >> Working Without a .NET? > >> http://classicvb.org/petition Karl E. Peterson - 18 Jul 2005 20:23 GMT Cool! :-D
 Signature Working Without a .NET? http://classicvb.org/petition
> Okay, I've got one here: http://www.officearticles.com/ > And I also have about 30,000 posts around the internet on forums, [quoted text clipped - 43 lines] >>>> Working Without a .NET? >>>> http://classicvb.org/petition
|
|
|