VBA, MS Access MS Access в примерах

Список принтеров в системе

По материалам: https://learn.microsoft.com/en-us/office/vba/access/concepts/printing/retrieve-a-list-of-installed-printers

Private Sub ShowPrinters()
'Список принтеров в системе
    Dim strCount As String
    Dim strMsg As String
    Dim prtLoop As Printer
    Dim iID As Integer
    On Error GoTo ShowPrinters_Err
 
    If Printers.Count > 0 Then
        ' Get count of installed printers.
        strMsg = "Printers installed: " & Printers.Count & vbCrLf & vbCrLf
     
        ' Enumerate printer system properties.
        For Each prtLoop In Application.Printers
            With prtLoop
                strMsg = strMsg _
                    & "Device ID: " & iID & vbCrLf _
                    & "Device name: " & .DeviceName & vbCrLf _
                    & "Driver name: " & .DriverName & vbCrLf _
                    & "Port: " & .Port & vbCrLf & vbCrLf
                    iID = iID + 1
            End With
        Next prtLoop
     
    Else
        strMsg = "No printers are installed."
    End If
     
    ' Display printer information.
    MsgBox strMsg, vbInformation, "Installed Printers"
    Debug.Print strMsg
     
ShowPrinters_End:
    Exit Sub
     
ShowPrinters_Err:
    MsgBox Prompt:=Err.Description, Buttons:=vbCritical & vbOKOnly, _
        Title:="Error Number " & Err.Number & " Occurred"
    Resume ShowPrinters_End
     
End Sub


Назад ToTop
L.E. 02.02.2023
Рейтинг@Mail.ru