Const HKLM = &H80000002 '定义根键常数
'其他常用根键 Const HKCR = &H80000000 , Const HKCU = &H80000001
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
oReg.EnumKey HKLM, strKeyPath, arrSubKeys '枚举子项,赋值给数组arrSubKeys
For Each subkey In arrSubKeys
Print subkey
Next
For Each x In Printers
FindPrinter strPrint, x.DeviceName
next
Function FindPrinter(ByRef PrinterName As String, Optional ByVal PrinterDescription As String = "") As Boolean
' 查指定打印机
Dim objRegistry As Object
Dim arrSubKeys As Variant
Dim subkey As Variant
Dim KeyValue As Variant
If Len(PrinterDescription) >0 Then
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
objRegistry.EnumValues &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", arrSubKeys
For Each subkey In arrSubKeys
If InStr(1, subkey, PrinterDescription) Then
objRegistry.GetStringValue &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\", subkey, KeyValue
PrinterName = subkey &" 在 " &Mid(KeyValue, InStr(KeyValue, ",") + 1, InStr(KeyValue, ":,") - InStr(KeyValue, ","))
FindPrinter = True
Exit For
End If
Next
Set objRegistry = Nothing
End If
End Function
选择打印机的方法有很多,你这样做也行,因为printform方法只打印到默认的打印机,照你的写法,你可以先用PRINTER取得默认打印的名字,me.printform完后。再将打印机设回,不过这方法不是最好的。如:
如果你的默认打印机名为
dim defPrinter as string
defPrinter = Printer.devicename
'*** 这里运行你的代码
Dim X As Printer
For Each X In Printers
if X.devicename = defPrinter then
Set Printer = X
exit for
end if
Next
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)