Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default How to check the existing of a printer?

Hi

How to check the existing of a printer?

Clara
--
thank you so much for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default How to check the existing of a printer?

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default How to check the existing of a printer?

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for existing data leonidas[_62_] Excel Programming 2 August 3rd 06 11:26 AM
Check Existing Button Mike[_101_] Excel Programming 1 October 27th 05 05:39 PM
Check for existing sheet in book benjammind Excel Programming 2 July 4th 05 01:53 PM
How to correct this formula and check if more issues are existing? Metallo[_3_] Excel Programming 9 October 27th 04 01:38 PM
Macro Help - check existing tabs Macro Help[_2_] Excel Programming 1 July 27th 04 05:15 PM


All times are GMT +1. The time now is 01:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"