Excel Print - Printer Selection

cshetty

Board Regular
Joined
Apr 15, 2017
Messages
76
Office Version
  1. 2016
Platform
  1. Windows
Dear Experts
I have a excel sheet, which I need to print on a particular printer due to page setup.

Code I use to print is as below

Sub PrintChq() Application.Dialogs(xlDialogPrinterSetup).Show Sheets("Sheet2").Select ActiveWindow.SelectedSheets.PrintOut Copies:=1 Sheets("Sheet1").Select End Sub

When I select print option, printer dialogue box appears and prints on selected printer. My problem is , when I press cancell on dialogue box, it still prints on default printer. I wish to abort printing when cancel button is clicked on print dialogue box.

Thank you.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Dear Experts
I have a excel sheet, which I need to print on a particular printer due to page setup.

Code I use to print is as below

Sub PrintChq() Application.Dialogs(xlDialogPrinterSetup).Show Sheets("Sheet2").Select ActiveWindow.SelectedSheets.PrintOut Copies:=1 Sheets("Sheet1").Select End Sub

When I select print option, printer dialogue box appears and prints on selected printer. My problem is , when I press cancell on dialogue box, it still prints on default printer. I wish to abort printing when cancel button is clicked on print dialogue box.

Thank you.
I made a small change and its fine now.

Sub PrintChq() Dim ans As Boolean ans = Application.Dialogs(xlDialogPrinterSetup).Show If ans = True Then Sheets("Sheet2").Select ActiveWindow.SelectedSheets.PrintOut Copies:=1 Else: Exit Sub End If Sheets("Sheet1").Select End Sub
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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