Sure thing!
Code:
Option Explicit
Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Function ChangeDefaultPrinter(p_strPrinterName As String) As Boolean
Dim prn As Printer
Dim blnIsFound As Boolean
Dim strBuffer As String
For Each prn In Printers
If UCase(p_strPrinterName) = UCase(prn.DeviceName) Then
strBuffer = prn.DeviceName & "," & prn.DriverName & "," & prn.Port
blnIsFound = True
Exit For
End If
Next
If blnIsFound Then
Call WriteProfileString("windows", "device", strBuffer)
ChangeDefaultPrinter = True
End If
End Function
Then you can call this function like this:
Code:
Private Sub Command1_Click()
Call ChangeDefaultPrinter("HP 2000C")
End Sub
Note: if you have network printers installed and
you want to change one of them to be your default printer, then you would have to pass full network path as a printer
name, i.e Call ChangeDefaultPrinter("\\ComputerName\HP 2000C")
Regards,