Display list of printers in combobox on userform
cs_Le Pivert Posted messages 8437 Status Contributor -
<font size="2">Hello everyone</font>
I have a little problem with a macro.
Indeed, when I run my macro, the list of printers is displayed in a combobox of a userform:
Printer name on PORTPROMPT:
Printer name on SHRFAX:
Printer name on USB002
Printer name on USB001
...ETC...
My wish is that I want the list to display as follows:
Printer name on Ne0..:
Printer name on Ne0..:
Printer name on Ne0..:
Printer name on Ne0..:
...ETC...
Here is the code I am using
'...………………………………………………………………………………………………………………………………………………………………..
Sub LISTE_IMPRIMANTE() Dim NomPC, Printer As String Dim ObjPrinter, ColInstalledPrinters, ObjWMiService As Object Dim i As Integer NomPC = "." Set ObjWMiService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & NomPC & "\root\cimv2") Set ColInstalledPrinters = ObjWMiService.ExecQuery("select * from win32_printer") For Each ObjPrinter In ColInstalledPrinters With Userform1 .ComboBox1.AddItem ObjPrinter.Name & " on " & ObjPrinter.PortName End With Next End Sub
'...………………………………………………………………………………………………………………………………………………………………..
Thank you in advance
5 answers
-
Hello, where does this Ne0 come from?
-
-
Let me explain
When I run the macro, the printer names display as, for example,
HP Deskjet 2700 series on PORTPROMPT:
instead of
HP Deskjet 2700 series on Ne05:
as I wish
-
The Ne05 comes from this Macro when it's launched
Sub Printer_Name ( )
Dim ComputerName, Printer As String Dim ObjPrinter, ColInstalledPrinters, ObjWMiService As Object Dim i As Integer ComputerName = "." Set ObjWMiService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2") Set ColInstalledPrinters = ObjWMiService.ExecQuery("select * from win32_printer")objPrinter = Application.activePrinter
Userform1.Combobox1.text = objPrinter
'Application.activePrinter=Userform1.Combobox1.text
End sub
-