Printing: VBA code to select printer

scotawful

Board Regular
Joined
Mar 6, 2003
Messages
148
Dear Excel Guru's,

I've got a delimma here. I've got a customized print macro that uses a userform to display all pages in a workbook that 1: have information on them and 2: are not hidden. The user simply checks off the sheets they want to print via checkboxes in the list, and then clicks "print".

What I'd like to do is also give the user the option to check off which printer they'd like the job to be sent to, as we've got about 5 different printers here each with their own area of specialty.

This may sound redundant with the already built-in print menu for excel, but the utility of this menu here has become pretty important.

I'm just looking for a snippet of code to get me off the ground on this one: something that detects the installed printing devices on the PC, if possible????
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Just for knowledge sharing...

Use this to determine if a print exists:

Code:
Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Long) As Long



Public Function GetPDC(ByVal strPrinter As String) As Long
    GetPDC = CreateIC("WINSPOOL", strPrinter, vbNullString, 0&)
End Function


Sub Look_For_Printer()

   printer_name = "Name found in the print setup drop down"
   If GetPDC( printer_name ) = 0 Then
      msgbox("This printer is not on this computer")
   end if

End Sub
 
Upvote 0
Here's how to print to a given printer without changing the computer settings....

Code:
dim myprinter as string
dim printer_name as sttring
printer_name ="name goes here"

    myprinter = Application.ActivePrinter
    Change_Form.PrintOut Preview:=False, ActivePrinter:=printer_name, PrintToFile:=True, PrToFileName:=PSFileName
    Application.ActivePrinter = myprinter
 
Upvote 0
Hi Excel Guru's,
Can some one help me with a complete code as how to select a printer(between 3 printers) using Macros. Hope I'm clear with my Question.

Many thanks!
 
Upvote 0
Hi Irish,
I tried using your code, as you have mentioned, I have changed printer_name with my printer name.,I'm getting an error as Invalid outside Procedure.


Can some one help me with a complete code as how to select a printer(between 3 printers) using Macros. Hope I'm clear with my Question.

Many thanks!
 
Upvote 0
Here is my suggestion, tested in Excel 2013, should be backwards compatible.

Code:
Sub iActiveSheet_Print()
' First choose a printer
    Application.Dialogs(xlDialogPrinterSetup).Show


' Make final arrangements and setup
    ActiveSheet.PrintPreview


' Print like there is no tomorrow
    ActiveSheet.PrintOut
End Sub

Of course the above may be adapted to your needs, be creative.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top