Weeble
Board Regular
- Joined
- Nov 30, 2016
- Messages
- 95
- Office Version
- 365
I found a code that could solve alot of my problems, but I get 'Run time Error 5 , Invalid procedure or Argument. Anyone that could help me out with the issue? Code is used for when printing lots of sheets, some papers are missing / skipps. This code is suppost to hold VBA until the sheet has been printed.
Code stops at this step.
Any help would be awesome, and let me know if you need more info.
I call WaitforPrintingToFinish in my original code.
Code stops at this step.
Code:
OpenPrinter Left(ActivePrinter, InStr(ActivePrinter, " o") - 1), hPrinter, ByVal 0&
Code:
Option Explicit
'' Win32 API declarations
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, pJob As Any, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Public Sub WaitForPrintingToFinish()
Do
Loop Until CountPrintJobs = 0
End Sub
Public Function CountPrintJobs() As Long
Dim hPrinter As Long, lNeeded As Long, lReturned As Long
Dim lJobCount As Long
OpenPrinter Left(ActivePrinter, InStr(ActivePrinter, " o") - 1), hPrinter, ByVal 0&
EnumJobs hPrinter, 0, 99, 1, ByVal 0&, 0, lNeeded, lReturned
If lNeeded > 0 Then
ReDim byteJobsBuffer(lNeeded - 1) As Byte
EnumJobs hPrinter, 0, 99, 1, byteJobsBuffer(0), lNeeded, lNeeded, lReturned
If lReturned > 0 Then
lJobCount = lReturned
Else
lJobCount = 0
End If
Else
lJobCount = 0
End If
ClosePrinter hPrinter
CountPrintJobs = lJobCount
End Function
Any help would be awesome, and let me know if you need more info.
I call WaitforPrintingToFinish in my original code.