Click here to copy the following block |
Public Function GetDefaultPrinter() As Printer Dim strBuffer As String * 254 Dim iRetValue As Long Dim strDefaultPrinterInfo As String Dim tblDefaultPrinterInfo() As String Dim objPrinter As Printer
iRetValue = GetProfileString("windows", "device", ",,,", strBuffer, 254) strDefaultPrinterInfo = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1) tblDefaultPrinterInfo = Split(strDefaultPrinterInfo, ",") For Each objPrinter In Printers If objPrinter.DeviceName = tblDefaultPrinterInfo(0) Then Exit For End If Next If objPrinter.DeviceName <> tblDefaultPrinterInfo(0) Then Set objPrinter = Nothing End If Set GetDefaultPrinter = objPrinter End Function |
Click here to copy the following block |
Private Sub Form_Load() Dim objPrinter As Printer
Set objPrinter = GetDefaultPrinter() MsgBox "Default printer is: " + objPrinter.DeviceName MsgBox "Driver name is: " + objPrinter.DriverName MsgBox "Port is: " + objPrinter.Port Set objPrinter = Nothing End Sub |
|