Microsoft Office Tutorials and References
In Depth Information
Windows API Calls
Figure 11-20: Using Windows API functions to get disk drive information.
Determining default printer information
The example in this section uses a Windows API function to return information about the active
printer. The information is contained in a single text string. The example parses the string and
displays the information in a more readable format.
Private Declare PtrSafe Function GetProfileStringA Lib “kernel32” _
(ByVal lpAppName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As _
String, ByVal nSize As Long) As Long
Sub DefaultPrinterInfo()
Dim strLPT As String * 255
Dim Result As String
Call GetProfileStringA _
(“Windows”, “Device”, “”, strLPT, 254)
Result = Application.Trim(strLPT)
ResultLength = Len(Result)
Comma1 = InStr(1, Result, “,”, 1)
Comma2 = InStr(Comma1 + 1, Result, “,”, 1)
‘ Gets printer’s name
Printer = Left(Result, Comma1 - 1)
‘ Gets driver
Driver = Mid(Result, Comma1 + 1, Comma2 - Comma1 - 1)
‘ Gets last part of device line
Port = Right(Result, ResultLength - Comma2)
‘ Build message
Msg = “Printer:” & Chr(9) & Printer & Chr(13)
Msg = Msg & “Driver:” & Chr(9) & Driver & Chr(13)
Msg = Msg & “Port:” & Chr(9) & Port
‘ Display message
MsgBox Msg, vbInformation, “Default Printer Information”
End Sub
 
Search JabSto ::




Custom Search