Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 38
Default List of printers

Hi

I'd like to get a array of all installed printers incl. the connected port.
The array should look like this:

HP LaserJet 6P on LPT1:
Adobe PDF on Ne03:
SnagIt 6 on Ne00:


I already have the following procedure, but this code doesn't return the
connected port:

Private Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub


Many thanks in advance.

Tom


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default List of printers

Hi Tom,
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print "Printer Port " & oPrinter.Item(iCount) & " = " &
oPrinter.Item(iCount + 1)
Next

MP

"Tom" a écrit dans le message de
...
Hi

I'd like to get a array of all installed printers incl. the connected

port.
The array should look like this:

HP LaserJet 6P on LPT1:
Adobe PDF on Ne03:
SnagIt 6 on Ne00:


I already have the following procedure, but this code doesn't return the
connected port:

Private Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub


Many thanks in advance.

Tom



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default List of printers

Re Tom, correction:
Debug.Print "Printer Port " & oPrinters.Item(iCount) _
& " = " & oPrinters.Item(iCount + 1)

MP

"Michel Pierron" a écrit dans le message de
...
Hi Tom,
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print "Printer Port " & oPrinter.Item(iCount) & " = " &
oPrinter.Item(iCount + 1)
Next

MP

"Tom" a écrit dans le message de
...
Hi

I'd like to get a array of all installed printers incl. the connected

port.
The array should look like this:

HP LaserJet 6P on LPT1:
Adobe PDF on Ne03:
SnagIt 6 on Ne00:


I already have the following procedure, but this code doesn't return the
connected port:

Private Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub


Many thanks in advance.

Tom




  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 38
Default List of printers

Thank u




"Michel Pierron" schrieb im Newsbeitrag
...
Re Tom, correction:
Debug.Print "Printer Port " & oPrinters.Item(iCount) _
& " = " & oPrinters.Item(iCount + 1)

MP

"Michel Pierron" a écrit dans le message de
...
Hi Tom,
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print "Printer Port " & oPrinter.Item(iCount) & " = " &
oPrinter.Item(iCount + 1)
Next

MP

"Tom" a écrit dans le message de
...
Hi

I'd like to get a array of all installed printers incl. the connected

port.
The array should look like this:

HP LaserJet 6P on LPT1:
Adobe PDF on Ne03:
SnagIt 6 on Ne00:


I already have the following procedure, but this code doesn't return
the
connected port:

Private Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub


Many thanks in advance.

Tom






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default List of printers

Hi Thomas

This should produce exactly what you're looking for
but note it will NOT work for xl97

The PrinterFind function will return an array of
localized strings ready to assign to the ActivePrinter.

I've amended an old post from myself to allow filtering.
see test procedure for example of how to use.
On a userform you could simply use s'th like
cboPrinters.list=PrinterFind





Option Explicit

Private Declare Function GetProfileString Lib "kernel32" _
Alias "GetProfileStringA" (ByVal lpAppName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long) As Long


Sub Test()
Dim vaList
'Get all printers
vaList = PrinterFind
'Show m
MsgBox Join(vaList, vbLf), , "List of printers"

'Get all laserjets
vaList = PrinterFind(Match:="Laserjet")

'Switch to the first laserjet found
If UBound(vaList) = -1 Then
MsgBox "Printer not found"
ElseIf MsgBox("from " & vbTab & ": " & ActivePrinter & vbLf & _
"to " & vbTab & ": " & vaList(0), _
vbOKCancel, "Switch Printers") = vbOK Then
Application.ActivePrinter = vaList(0)
End If
End Sub

Public Function PrinterFind(Optional Match As String) As String()
Dim n%, lRet&, sBuf$, sCon$, aPrn$()
Const lLen& = 1024, sKey$ = "devices"

'------------------------------------------------------------------
'written by keepITcool

'requires xl2000 or newer.
'returns a zerobased array of complete localized printer strings
'results are filtered on Match string, if no result the ubound = -1
'------------------------------------------------------------------

'Split ActivePrinter string to get localized word for "on"
aPrn = Split(Excel.ActivePrinter)
sCon = " " & aPrn(UBound(aPrn) - 1) & " "

'Read all installed printers (1k bytes s/b enough)
sBuf = Space(lLen)
lRet = GetProfileString(sKey, vbNullString, vbNullString, sBuf, lLen)
If lRet = 0 Then
Err.Raise vbObjectError + 513, , "Can't read Profile"
Exit Function
End If

'Split buffer string
aPrn = Split(Left(sBuf, lRet - 1), vbNullChar)
'Filter array on Match
If Match < vbNullString Then aPrn = Filter(aPrn, Match, -1, 1)

For n = LBound(aPrn) To UBound(aPrn)
'Add 16bit portname for each Printer
sBuf = Space(lLen)
lRet = GetProfileString(sKey, aPrn(n), vbNullString, sBuf, lLen)
aPrn(n) = aPrn(n) & sCon & _
Mid(sBuf, InStr(sBuf, ",") + 1, lRet - InStr(sBuf, ","))
Next
'Return the result
PrinterFind = aPrn

End Function






--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Tom wrote :

Hi

I'd like to get a array of all installed printers incl. the connected
port. The array should look like this:

HP LaserJet 6P on LPT1:
Adobe PDF on Ne03:
SnagIt 6 on Ne00:


I already have the following procedure, but this code doesn't return
the connected port:

Private Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub


Many thanks in advance.

Tom

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
List of available printers prizm1 New Users to Excel 3 June 12th 05 01:32 PM
list o installed printers Arkaad Excel Programming 1 September 14th 04 10:52 AM
How to get the available printers list in a macro [email protected] Excel Programming 3 March 5th 04 02:54 PM
Creating a printers list PO Excel Programming 2 November 14th 03 01:51 PM
List of Printers Bret Holle Excel Programming 1 September 27th 03 04:39 PM


All times are GMT +1. The time now is 09:43 AM.

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

About Us

"It's about Microsoft Excel"