首页 > 编程语言 > 详细

VBA Find Printers

时间:2016-07-11 12:11:37      阅读:317      评论:0      收藏:0      [点我收藏+]
Public Function FindPrinter(strPrinterName As String) As Boolean
    Dim pa As String
    Dim length As Integer
    Dim objRegistry As Object
    Dim arrSubkeys As Variant
    Dim subkey As Variant
    Dim kk As Variant
    
    
    On Error Resume Next
    Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
    
    objRegistry.EnumValues &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", arrSubkeys
    FindPrinter = False
    length = Len(strPrinter)
    For Each subkey In arrSubkeys
        objRegistry.GetStringValue &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\", subkey, kk
        pa = subkey & " on " & Mid(kk, InStr(kk, ",") + 1, InStr(kk, ":,") - InStr(kk, ","))
        
        If Left(pa, length) = strPrinterName Then
            FindPrinter = True
            Application.ActivePrinter = pa
            Exit For
        End If
    Next
    
    If FindPrinter = False Then
        MsgBox "没有找到打印机。"
    End If
    
End Function

 

VBA Find Printers

原文:http://www.cnblogs.com/mymeng_feng/p/4359270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!