VB Code:
Option Explicit
Private 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
Private Sub Command1_Click()
'=====================================
Dim prt As Printer, prtName As String
prtName = GetDefaultPrinter
For Each prt In Printers
If prt.DeviceName = prtName Then
Set Printer = prt
Exit For
End If
Next
'Label1.Caption = "Default Printer: " & Printer.DeviceName
Debug.Print "Default Printer: " & Printer.DeviceName
'you may now proceed with your printing
'Printer.Copies = intNumCopies
End Sub
Public Function GetDefaultPrinter() As String
'=============================================
Dim def$, di&, Pos&
def = String$(128, 0)
di = GetProfileString("WINDOWS", "DEVICE", "", def, 127)
def = Left(def, di)
Pos = InStr(1, def, ",")
GetDefaultPrinter = Left(def, Pos - 1)
End Function