Display list of printers in combobox on userform

arobase_GDM -  
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

  1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassador 1 588
     

    Hello, where does this Ne0 come from?

    0
  2. Arobase_GDM
     

    It is the name of the port in the PC system where each printer is located.

    0
    1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
       

      Can you be more specific: what does this name refer to precisely?

      0
  3. Arobase_GDM
     

    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

    0
    1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
       

      Where does this Ne05 come from? What does it mean? Where can you see it on your computer?

      0
  4. Arobase_GDM
     

    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

    0
    1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
       

      I don't see it Ne05.

      0
  5. cs_Le Pivert Posted messages 8437 Status Contributor 731
     

    Hello,

    You will find your answer HERE


    0