PDA

View Full Version : [SOLVED] Can I use vba to clear failed print jobs?



frank_m
10-28-2010, 05:50 AM
I would like to know if there is a way that I can have a printing macro exit if the default printer is powered off.

- Also I would like to know if there is vba code that can clear print jobs that are waiting.

Thanks

frank_m
10-28-2010, 09:52 PM
I came up with a batch file that can do what I want, but in Windows Vista Home I have to run it by right clicking and choosing run as Administrator, so I'm looking for a way to call up the permission prompt either in the batch file or vba.

I posted the question pertaining to the batch file in the "Other Applications Help" section of this forum. http://www.vbaexpress.com/forum/showthread.php?p=228561#post228561

The Batch file code is;

@echo off
cls
net stop spooler
del %systemroot%\system32\spool\printers\*.shd
del %systemroot%\system32\spool\printers\*.spl
net start spooler

frank_m
10-29-2010, 01:45 AM
I got it worked out.

Created a shortcut to the batch file. Renamed the shortcut "ClearPrintJobs" without the quotes and did not include the extension .lnk into the name.
Then I Right clicked on the shortcut, selected properties > the advanced button > checked the Run as Administrator checkbox,(Note: Only a short cut has the run as Administrator check box, if you check properties for a batch file there is no such option)
- Then with the code authored by Hermanito at http://www.mrexcel.com/forum/showthread.php?p=1498822
I substituted in shortcut name including the .lnk extension and changed the vbhide Shell Parameter to 1, as to avoid the Administrator prompt from being minimized to the task bar. - It works :thumb

Sub RunClearPrintJobsBatchFileShortcut()
Dim FileName As String
FileName = Environ("USERPROFILE") & "\Desktop\" & "ClearPrintJobs.lnk"
FileName = "cmd /c " & """" & FileName & """"
Call Shell(FileName, 1)
End Sub