【译文】如何检索已安装打印机的列表-周芳
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


【译文】如何检索已安装打印机的列表

发表时间:2013/12/31 8:35:39 评论(4) 浏览(6731)  评论 | 加入收藏 | 复制
   
摘 要:如何检索已安装打印机的列表
正 文:

来自:微软    翻译:周芳

【译文 如何检索已安装打印机的列表


      使用打印机属性应用程序对象来返回打印机集。下面的程序演示了如何使用For Each…Next 语句来通过每个打印机对象遍历打印机。消息框来显示每个安装的打印机的信息。


VBA代码:
Sub ShowPrinters()
    Dim strCount As String
    Dim strMsg As String
    Dim prtLoop As Printer
    
    On Error GoTo ShowPrinters_Err
 
    If Printers.Count > 0 Then
        ' 获取已安装打印机数目.
        strMsg = "Printers installed: " & Printers.Count & vbCrLf & vbCrLf
    
        ' 列举出打印系统的属性.
        For Each prtLoop In Application.Printers
            With prtLoop
                strMsg = strMsg _
                    & "Device name: " & .DeviceName & vbCrLf _
                    & "Driver name: " & .DriverName & vbCrLf _
                    & "Port: " & .Port & vbCrLf & vbCrLf
            End With
        Next prtLoop
    
    Else
        strMsg = "没有安装打印机."
    End If
    
    ' 显示打印机信息.
    MsgBox Prompt:=strMsg, Buttons:=vbOKOnly, Title:="Installed Printers"
    
ShowPrinters_End:
    Exit Sub
    
ShowPrinters_Err:
    MsgBox Prompt:=Err.Description, Buttons:=vbCritical & vbOKOnly, _
        Title:="Error Number " & Err.Number & " Occurred"
    Resume ShowPrinters_End
    
End Sub



【原文】How to: Retrieve a List of Installed Printers

       You use the Printers property of the Application object to return the Printers collection. The following procedure illustrates how to enumerate through each Printer object in the Printers collection by using a For Each…Next statement. A message box is displayed with information about each installed printer.

VBA:
Sub ShowPrinters()
    Dim strCount As String
    Dim strMsg As String
    Dim prtLoop As Printer
    
    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 name: " & .DeviceName & vbCrLf _
                    & "Driver name: " & .DriverName & vbCrLf _
                    & "Port: " & .Port & vbCrLf & vbCrLf
            End With
        Next prtLoop
    
    Else
        strMsg = "No printers are installed."
    End If
    
    ' Display printer information.
    MsgBox Prompt:=strMsg, Buttons:=vbOKOnly, Title:="Installed Printers"
    
ShowPrinters_End:
    Exit Sub
    
ShowPrinters_Err:
    MsgBox Prompt:=Err.Description, Buttons:=vbCritical & vbOKOnly, _
        Title:="Error Number " & Err.Number & " Occurred"
    Resume ShowPrinters_End
    
End Sub


Access软件网交流QQ群(群号:198465573)
 
 相关文章
【译文】如何使用自定义条件删除记录  【周芳  2013/11/19】
【译文】如何允许用户为未绑定的组合框添加项目  【周芳  2013/11/26】
【译文】如何在子窗体或者子报表中调用程序  【周芳  2013/12/10】
【译文】为什么使用Access作为开发工具  【周芳(译)  2013/12/17】
【译文】如何用ADO代码实现窗体记录集的绑定  【周芳  2013/12/24】
常见问答
技术分类
相关资源
文章搜索
关于作者

周芳

文章分类

文章存档

友情链接