Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHECK if the job print is finished 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
428
IT
CHECK if the job print is finished and return if exist error on printer...
idea?

i use:
...
XLAPP.Activesheet.PrintOut Copies:=1, Collate:=True
...
 
Here's some simple code that shows you how to get a number of properties for the printer your Excel app is using. It is NOT a code solution to "CHECK if the job print is finished and return if exist error on printer.", but provides all the info you need to write such code yourself

Code:
[COLOR=blue]XLAPP.ActiveSheet.PrintOut Copies:=1, Collate:=True [COLOR=green]' submit print job as per sal21[/color] 

Set PrinterSet = GetObject("winmgmts:").InstancesOf("Win32_Printer")
If (PrinterSet.Count = 0) Then Debug.Print "No Printers Installed!"
For Each oPrinter In PrinterSet
    If oPrinter.Name = Left(XLAPP.ActivePrinter, InStr(XLAPP.ActivePrinter, " on") - 1) Then 
        If oPrinter.PrinterStatus = 2 Then Debug.Print oPrinter.Name & Chr(13) & "Status:  Error, " & oPrinter.ErrorDescription
        If oPrinter.PrinterStatus = 3 Then Debug.Print oPrinter.Name & Chr(13) & "Status:  Idle"
        If oPrinter.PrinterStatus = 4 Then Debug.Print oPrinter.Name & Chr(13) & "Status:  Printing"
    End If
Next[/color]


If needing more properties, have a look here
 
Tks strongm!

but here:
If oPrinter.Name = Left(XLAPP.ActivePrinter, InStr(XLAPP.ActivePrinter, " on") - 1) Then

error5: invalid procedure call or argument


and you dont have dimensioned this 2 var
oPrinter
PrinterSet
 
> you dont have dimensioned this 2 var

I know, but I assumed that since you designate yourself as a programmer, you'd be able to provide the necessary supportive plumbing, whilst I focussed on providing some key lines of code to help you build the solution you want rather than writing your program for you. Note I don't Dim or assign XLAPP either

>error5: invalid procedure call or argument
Yep, that can happen with this example code depending on the contents of XLAPP.ActivePrinter.

But again, this should not matter to a programmer. You should be able to see what this line of code is supposed to be doing (matching Excel's active printer name with the name of an attached printer). On my system, the ActivePrinter string actually consists of the printer name plus the connection it is on (e.g "Microsoft Print to PDF on NE0:"), and so the example clips off the extra text. But if the extra text is missing, you get the error you mention

try the following instead:

If oPrinter.Name = Left(XLAPP.ActivePrinter, Len(oPrinter.Name)) Then
 
in other case my code to identify XLAPP..

Code:
 Dim XLWB As Object, WS As Object, XLAPP As Object
    Set XLAPP = CreateObject("Excel.Application")
    Set XLWB = XLAPP.Workbooks.Open(FileName:=STRWB, Editable:=True)
    Set WS = XLWB.Worksheets("REPORT")
    WS.Range("B2:AZ51").ClearContents

    CONTA = 0

    With WS
        .Application.ScreenUpdating = False
        For K = 0 To UBound(strDBRows_ESTRAI, 2)
            .Cells(strDBRows_ESTRAI(3, K) + 1, strDBRows_ESTRAI(4, K) + 1) = "X"
            .Cells(strDBRows_ESTRAI(3, K) + 1, 52) = .Cells(strDBRows_ESTRAI(3, K) + 1, 52) + 1
            CONTA = CONTA + 1
            DoEvents
        Next K
        .Application.ScreenUpdating = True
        'IMPOSTAZIONI PAGINA DI STAMPA
        DXSX = DXSX & "X"
        .PageSetup.CenterHeader = "REPORT OMBRELLONI DEL: " & Format(GIORNO, "DD/MM/YYYY") & " - (ZONA: " & DXSX & ")"
        .PageSetup.LeftFooter = "REPORT STAMPATO IL:  " & Format(Date, "DD/MM/YYYY")
        .PageSetup.RightFooter = "OMBRELLONI PRENOTATI NR:  " & CONTA
        .PageSetup.PaperSize = vbPRPSA4
        'IMPOSTAZIONI PAGINA DI STAMPA

         XLAPP.Activesheet.PrintOut Copies:=1, Collate:=True
    
    End With
 
Yes, I already knew how to get XLAPP. My point was I didn't include it in my code example because you, of course, would already know it. And I assumed you could work out for yourself how to declare the other two variables (and I'm going to continue in that assumption). To be clear, the code snippet I provided was not air code. It was extracted from a working example.

Did you try making the change to the [tt]If oPrinter.Name[/tt] line that I suggested above to avoid Error 5?
 
Did you try making the change to the If oPrinter.Name line that I suggested above to avoid Error 5?

yES! modified and work.
 
How about marking the helpful post(s) with a Star by clicking on [blue]Great post![/blue]


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top