【译文】如何检索已安装打印机的列表
时 间:2013-12-31 08:35:39
作 者:周芳 ID:24526 城市:上海
摘 要:如何检索已安装打印机的列表
正 文:
来自:微软 翻译:周芳
【译文】 如何检索已安装打印机的列表
使用打印机属性应用程序对象来返回打印机集。下面的程序演示了如何使用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群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)
- Access快速开发平台--让有权...(11.04)
- Access快速开发平台--审批选...(11.01)
- ACCESS两张表先各自排序,然后...(10.31)
- Access对子窗体数据进行批量+...(10.30)
- SqlServer中如何用SQL命...(10.29)
- Access报表中的分组功能用代码...(10.28)
- 用Access计算库存结余的一个方...(10.26)
- 最精简的组合框行来源数据快速输入(...(10.25)