by Duncan Jones (19 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(11 Votes)
Temporarily change the currently selected (default) printer within your VB program
Assumes
This doesn't save the change to the registry - which needs to be done for a permanent change of default printer.
API Declarationsn/a
Public Function SetDefaultPrinter(ByVal DeviceName As String) As Boolean
Dim prThis As Printer
If Printers.Count > 0 Then
'\\ Iterate through all the installed printers
For Each prThis In Printers
'\\ If the desired one is found
If prThis.DeviceName = DeviceName Then
Set Printer = prThis
SetDefaultPrinter = True
'\\ Stop searching
Exit For
End If
Next prThis
End If
End Function