HI Anony,
Thank you for your code. It can detect a printer's profile. What I really
want to need as follow:
before printing, I want to check whether the printer is in normal work
mode, such as network cable is connected, there is paper ect.
Is it possible to do it?
Thank you very much
Clara
--
thank you so much for your help
"Anony" wrote:
> To check the existence of a printer and display the name of the existing
> printer, copy this code into a normal VBA module and run it:
>
>
> Private Declare Function GetProfileStringA Lib "kernel32" _
> (ByVal lpApplName As String, ByVal lpKeyName As String, _
> ByVal lpDefault As String, ByVal lpReturnedString As _
> String, ByVal nSize As Long) As Long
>
> Sub Printer()
> Dim strLPT As String * 255
> Dim Result As String
> Dim Resultlength, Comma1, Comma2
> Dim Printer As String, Driver As String, Port As String
> Dim Msg As String
>
> Call GetProfileStringA("Windows", "Device", "", strLPT, 254)
>
> On Error Resume Next
> Result = Application.Trim(strLPT)
> Resultlength = Len(Result)
> If Err <> 0 Then
> MsgBox "No printer detected.", vbInformation, "Printer"
> Exit Sub
> End If
> On Error GoTo 0
>
> Comma1 = InStr(1, Result, ",", 1)
> Comma2 = InStr(Comma1 + 1, Result, ",", 1)
>
> Printer = Left(Result, Comma1 - 1)
> If Printer = "" Then
> MsgBox "No printer detected.", vbInformation, "Printer"
> Exit Sub
> End If
>
> Msg = "Printer: " & Printer & vbCrLf
> MsgBox Msg, , "Existing Printer"
>
> End Sub
|