ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Printer Selection (https://www.excelbanter.com/excel-programming/345987-printer-selection.html)

Hal[_4_]

Printer Selection
 
Greetings Time Travelers. . . Sorry wrong group. And now for something
completely on topic.

I have an Excel app that must print to an impact printer. This printer is
not the default printer. I would like to have Excel do the work in selecting
this specific printer when the app runs. Of course it should return the
previously selected default printer as such.

For this to work effortlessly, a check for a specific printer would need to
be made. If it does not exist print nothing and exit. This is not a networked
printer (yet) and can not be easily selected if it is not already installed.

Your help in developing code to check for and select a specific printer is
greatly appreciated.

Hal
Detroit, MI


Tom Ogilvy

Printer Selection
 
http://support.microsoft.com/?ID=166008
ACC: Enumerating Local and Network Printers

Enumerating Windows' Available Ports
http://www.mvps.org/vbnet/code/enums/enumports.htm
=======================

Posting by KeepItcool

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 showlist()
MsgBox Join(PrinterList, vbNewLine)
End Sub


Function PrinterList()
Dim lRet As Long
Dim sBuffer As String
Dim lSize As Long
Dim avTmp As Variant
Dim aPrn() As String
Dim n%, sPrn$, sConn$, sPort$

'Get localized Connection string
avTmp = Split(Excel.ActivePrinter)
sConn = " " & avTmp(UBound(avTmp) - 1) & " "
'Get Printers
lSize = 1024
sBuffer = Space(lSize)
lRet = GetProfileString("devices", vbNullString, vbNullString, _
sBuffer, lSize)
sBuffer = Left(sBuffer, lRet)
avTmp = Split(sBuffer, Chr(0))

ReDim Preserve avTmp(UBound(avTmp) - 1)
For n = 0 To UBound(avTmp)
lSize = 128
sBuffer = Space(lSize)
lRet = GetProfileString("devices", avTmp(n), vbNullString, _
sBuffer, lSize)
sPort = Mid(sBuffer, InStr(sBuffer, ",") + 1, _
lRet - InStr(sBuffer, ","))
avTmp(n) = avTmp(n) & sConn & sPort
Next
PrinterList = avTmp
End Function


--
Regards,
Tom Ogilvy

"Hal" wrote in message
...
Greetings Time Travelers. . . Sorry wrong group. And now for something
completely on topic.

I have an Excel app that must print to an impact printer. This printer is
not the default printer. I would like to have Excel do the work in

selecting
this specific printer when the app runs. Of course it should return the
previously selected default printer as such.

For this to work effortlessly, a check for a specific printer would need

to
be made. If it does not exist print nothing and exit. This is not a

networked
printer (yet) and can not be easily selected if it is not already

installed.

Your help in developing code to check for and select a specific printer is
greatly appreciated.

Hal
Detroit, MI





All times are GMT +1. The time now is 10:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com