显示具有特定名称的打印机

Show Printers with specific name

我有一些代码列出了所有活动的打印机(但在 msgboxes 而不是列表中这样做)。我对该功能没有问题。这是下面的代码:

    If Printers.Count > 0 Then
    strMsg = "Printers installed: " & Printers.Count & vbCrLf & vbCrLf
    For Each prtLoop In Application.Printers
        With prtLoop
           MsgBox .DeviceName                
      End With
    Next prtLoop
    Else
    MsgBox "No printers are installed."
    End If

虽然它做了我本质上需要它做的事情,但我希望它只在打印机与代码中设置的打印机名称的一部分匹配时弹出。例如,如果我有 3 台打印机:

Printer ABC 1
Printer ZZ5 2 (copy)
Printer 123

我希望在

之后可能有一个 If Then 语句
    For Each prtLoop In Application.Printers

上面的代码部分表示如果设备名称是 *ABC 那么它只会弹出 "Printer ABC 1" 而不是全部 3.

我希望这是有道理的。先谢谢您的帮助。 -弗拉基米尔

也许这就是你想做的?
如果Printers.Count > 0 那么 strMsg = "Printers installed: " & Printers.Count & vbCrLf & vbCrLf 对于 Application.Printers 中的每个 prtLoop 使用 prtLoop 如果 InStr(DeviceName, "ABC") 那么 MsgBox .DeviceName<br> 结束如果<br> 结束于 下一个循环 别的 消息框 "No printers are installed." 结束如果

编辑:Access 不喜欢 If then 语句,因为它是一行,错误出现 "End If without Block If" 错误,我将 MsgBox .DeviceName 移到它自己的行并且它有效。