ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Printers (https://www.excelbanter.com/excel-programming/347006-printers.html)

Jason Zischke

Printers
 
Is there a way for VB Excel to list all the avalable printers on your
computer in a ComboBox.

chijanzen

Printers
 
Jason:

try,

Private Declare Sub RtlMoveMemory Lib "Kernel32" (pDest As Long, _
ByVal pSource As Long, ByVal Length As Long)

Private Declare Function lstrlenA Lib "Kernel32" _
(ByVal lpString As Any) As Long

Private Declare Function lstrcpyA Lib "Kernel32" _
(ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Declare Function EnumPrintersA Lib "Winspool.drv" _
(ByVal flags As Long, ByVal name As String, ByVal Level As Long, _
pPrinterEnum As Long, ByVal cdBuf As Long, _
pcbNeeded As Long, pcReturned As Long) As Long
Private Sub UserForm_Initialize()
Dim PrinterEnum() As Long, Impr As String
Dim Needed As Long, Returned As Long, I As Integer
Dim Res As Long
EnumPrintersA 2, vbNullString, 2, 0, 0, Needed, 0
If Needed = 0 Then MsgBox "Erreur", vbCritical: Exit Sub
ReDim PrinterEnum(Needed / 4)
If EnumPrintersA(2, vbNullString, 2, PrinterEnum(0), Needed, _
Needed, Returned) = 0 Then MsgBox "Erreur", vbCritical: Exit Sub
For I = 1 To Returned * 21 Step 21
Impr = Space$(lstrlenA(PrinterEnum(I)))
lstrcpyA Impr, PrinterEnum(I)
If PrinterEnum(I + 6) Then _
RtlMoveMemory Res, PrinterEnum(I + 6) + 58, 2
k = k + 1
Me.ComboBox1.AddItem Impr
Next I

End Sub

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"Jason Zischke" wrote:

Is there a way for VB Excel to list all the avalable printers on your
computer in a ComboBox.


chijanzen

Printers
 
Jason:

or Use Dialogs


Dim DialogPrinter As Boolean
Dim ptr_name As String
DialogPrinter = Application.Dialogs(xlDialogPrinterSetup).Show
If DialogPrinter = False Then Exit Sub
ptr_name = Application.ActivePrinter
ptr_name = Left(ptr_name, InStr(1, ptr_name, " on") - 1)
ActiveWorkbook.PrintOut From:=1, To:=1, Copies:=1, Collate:=True

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"Jason Zischke" wrote:

Is there a way for VB Excel to list all the avalable printers on your
computer in a ComboBox.


Norman Jones

Printers
 
Hi Jason,

Try:
'==========
Private Sub UserForm_Activate()
ListPrinters
End Sub
'<<==========


'==========
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
ComboBox1.AddItem oPrinters.Item(iCount + 1)
Next
End Sub

'<<==========


---
Regards,
Norman



"Jason Zischke" wrote in message
...
Is there a way for VB Excel to list all the avalable printers on your
computer in a ComboBox.




Jason Zischke

Printers
 
Thanks chijanzen,

That worked but is there a way to list avalable printers from networked
computers also.

"chijanzen" wrote:

Jason:

try,

Private Declare Sub RtlMoveMemory Lib "Kernel32" (pDest As Long, _
ByVal pSource As Long, ByVal Length As Long)

Private Declare Function lstrlenA Lib "Kernel32" _
(ByVal lpString As Any) As Long

Private Declare Function lstrcpyA Lib "Kernel32" _
(ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Declare Function EnumPrintersA Lib "Winspool.drv" _
(ByVal flags As Long, ByVal name As String, ByVal Level As Long, _
pPrinterEnum As Long, ByVal cdBuf As Long, _
pcbNeeded As Long, pcReturned As Long) As Long
Private Sub UserForm_Initialize()
Dim PrinterEnum() As Long, Impr As String
Dim Needed As Long, Returned As Long, I As Integer
Dim Res As Long
EnumPrintersA 2, vbNullString, 2, 0, 0, Needed, 0
If Needed = 0 Then MsgBox "Erreur", vbCritical: Exit Sub
ReDim PrinterEnum(Needed / 4)
If EnumPrintersA(2, vbNullString, 2, PrinterEnum(0), Needed, _
Needed, Returned) = 0 Then MsgBox "Erreur", vbCritical: Exit Sub
For I = 1 To Returned * 21 Step 21
Impr = Space$(lstrlenA(PrinterEnum(I)))
lstrcpyA Impr, PrinterEnum(I)
If PrinterEnum(I + 6) Then _
RtlMoveMemory Res, PrinterEnum(I + 6) + 58, 2
k = k + 1
Me.ComboBox1.AddItem Impr
Next I

End Sub

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"Jason Zischke" wrote:

Is there a way for VB Excel to list all the avalable printers on your
computer in a ComboBox.



All times are GMT +1. The time now is 06:51 AM.

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