【问题标题】:Show Printers with specific name显示具有特定名称的打印机
【发布时间】:2017-01-23 14:13:49
【问题描述】:

我有一些代码列出了所有活动的打印机(但在 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。

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

【问题讨论】:

    标签: vba ms-access printing device-name


    【解决方案1】:

    也许这就是你想做的?
    If Printers.Count > 0 Then strMsg = "Printers installed: " & Printers.Count & vbCrLf & vbCrLf For Each prtLoop In Application.Printers With prtLoop If InStr(DeviceName, "ABC") Then MsgBox .DeviceName
    End If
    End With Next prtLoop Else MsgBox "No printers are installed." End If

    编辑:Access 不喜欢 If then 语句,因为它是一行,出现“End If without Block If”错误,我将 MsgBox .DeviceName 移动到它自己的行,它可以工作。

    【讨论】:

    • 谢谢马蒂亚斯!!!这很棒。我确实做了一个小改动,因为 Access 抛出了一个错误(End if without block if),因为 MsgBox .Devicename 在同一行,在我将它移到它自己的行之后没有更多错误并且它工作正常。
    猜你喜欢
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多