Custom Search

Friday, November 28, 2008

Get the systems default printer

Public Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" _
(ByVal lpAppName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long) As Long


'-------------------------------------------------------------

Public Function DefaultPrinter() As String

Dim strReturn As String
Dim intReturn As Integer

strReturn = Space(255)

'This gets the default printer name
intReturn = GetProfileString("Windows", ByVal "device", "", _
strReturn, Len(strReturn))

If intReturn Then
strReturn = UCase(Left(strReturn, InStr(strReturn, ",") - 1))
End If

DefaultPrinter = strReturn

End Function

No comments: