Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Active Printer Application

I have a workbook with a VB code to choose a non-network printer and print a
document. The application code currently being used is:

Application.ActivePrinter = "hp photosmart p1110 series on LPT1:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"hp photosmart p1100 series on LPT1:", Collate:=True

This code works very well for this particular printer connected by parallel
cable to this particular port. However, I need an application syntax which
will work universally for any hp photosmart printer, disregarding any
particular model or whether it is a parallel or USB connection. Any
suggestions? Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Active Printer Application

You might try this code which attempts to return the name of an installed
printer that matches a partial name.


Const PRINTER_ENUM_CONNECTIONS = &H4
Const PRINTER_ENUM_LOCAL = &H2
Declare Function EnumPrinters Lib "winspool.drv" Alias _
"EnumPrintersA" (ByVal flags As Long, _
ByVal xName As String, ByVal Level As Long, _
pPrinterEnum As Long, ByVal cdBuf As Long, _
pcbNeeded As Long, pcReturned As Long) As Long

Declare Function PtrToStr Lib "Kernel32" Alias "lstrcpyA" _
(ByVal RetVal As String, ByVal Ptr As Long) As Long

Declare Function StrLen Lib "Kernel32" Alias "lstrlenA" _
(ByVal Ptr As Long) As Long

Sub TestFunc()
MsgBox GetPrnName("hp photosmart*")
End Sub

Function GetPrnName(Template As String) As String
Dim cbRequired As Long, cbBuffer As Long
Dim Buffer() As Long, nEntries As Long
Dim I As Long, PDesc As String, Try2 As Boolean
cbBuffer = 3000
TryAgain:
ReDim Buffer((cbBuffer \ 4) - 1)
If EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
PRINTER_ENUM_LOCAL, "", 1, Buffer(0), cbBuffer, _
cbRequired, nEntries) Then
For I = 0 To nEntries - 1
PDesc = Space$(StrLen(Buffer(I * 4 + 2)))
PtrToStr PDesc, Buffer(I * 4 + 2)
If LCase(PDesc) Like LCase(Template) Then
GetPrnName = PDesc
Exit For
End If
Next
Else
If Not Try2 Then
Try2 = True
cbBuffer = cbRequired
GoTo TryAgain
End If
End If
End Function


--
Jim Rech
Excel MVP
"Larry" wrote in message
...
|I have a workbook with a VB code to choose a non-network printer and print
a
| document. The application code currently being used is:
|
| Application.ActivePrinter = "hp photosmart p1110 series on LPT1:"
| ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
| "hp photosmart p1100 series on LPT1:", Collate:=True
|
| This code works very well for this particular printer connected by
parallel
| cable to this particular port. However, I need an application syntax
which
| will work universally for any hp photosmart printer, disregarding any
| particular model or whether it is a parallel or USB connection. Any
| suggestions? Thanks for your help.


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
How to set printer default to select active sheet not whole book Vic Storey Excel Discussion (Misc queries) 0 May 16th 08 06:11 PM
How to Determine if Application Window Still Active Edwin Kelly Excel Discussion (Misc queries) 3 June 26th 07 05:42 PM
Active printer Marijan Glavac Excel Programming 1 September 29th 04 01:41 PM
Active application sp00nix[_3_] Excel Programming 0 July 21st 04 04:34 PM
Resetting the Active Printer Sue[_5_] Excel Programming 1 January 15th 04 01:20 AM


All times are GMT +1. The time now is 08:23 PM.

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"