Printers 集合包含代表當前系統(tǒng)中所有可用打印機的 Printer 對象。
使用 Application 對象的 Printers 屬性可以返回 Printers 集合。使用 For Each...Next 語句,可以循環(huán)遍歷 Modules 集合。下面的示例顯示系統(tǒng)所有可用打印機的有關信息。
For Each prtLoop In Application.Printers
With prtLoop
MsgBox "Device name: " & .DeviceName & vbCr _
& "Driver name: " & .DriverName & vbCr _
& "Port: " & .Port
End With
Next prtLoop
通過按名稱或按其在集合中的索引引用打印機,可以引用 Printers 集合中的單個 Printer 對象。
Printers 集合的索引從零開始。如果按其索引來引用打印機,則第一臺打印機是 Printers(0),第二臺打印機是 Printers(1),以此類推。
不能在 Printers 集合中添加或刪除 Printer 對象。