README.md

December 5, 2022 ยท View on GitHub

Change selected printer

Description

Temporarily change the currently selected (default) printer within your VB program

More Info

This doesn't save the change to the registry - which needs to be done for a permanent change of default printer.

Submitted On
ByDuncan Jones
LevelBeginner
User Rating4.1 (45 globes from 11 users)
CompatibilityVB 5.0, VB 6.0
CategoryMiscellaneous
WorldVisual Basic
Archive File

Source Code

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