VBA Code to Select "Cancel" when "Printer Setup" dialog box appears

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
572
Office Version
  1. 365
Platform
  1. Windows
Can anyone tell me how I would get the "Cancel" button to select "Cancel" when the "Printer Setup" dialog box appears? I'm asking because I only want the "Print" window that has all the options for the Margins, Orientation and so on to appear.

When I use the following:
VBA Code:
Application.Dialogs(xlDialogPrinterSetup).Show

A "Printer Setup" dialog box appears. Then I have to select "Cancel" in order to be taken to the "Print" screen next. Not sure if there is another way to bypass that "Printer Setup" dialog box or not.

Also, I want my code to set the print area to be the "Print Active Sheets" option.


Thank you, SS
 
Application.Dialogs(xlDialogPrint).Show always defaults to "Print Active Sheets" Isn't that what you want ?
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Application.Dialogs(xlDialogPrint).Show always defaults to "Print Active Sheets" Isn't that what you want ?
No, because the only way out of that dialog box is either to print or cancel out. I don't want to print and I just want the setting in the file to be at "Print Active Sheets". So when the next person opens it, the setting will be correct and I don't have to print to make it that way. See post #10. Thanks, Steve
 
Upvote 0
Application.Dialogs(xlDialogPrint).Show
If you Cancel the dialog , the "Print Active Sheets" always sticks as it is the default setting.

What you asked in post#10 will be difficult to achieve even using Microsoft Acceesibility.

Sendkeys is not reliable either
 
Upvote 0
Application.Dialogs(xlDialogPrint).Show
If you Cancel the dialog , the "Print Active Sheets" always sticks as it is the default setting.

What you asked in post#10 will be difficult to achieve even using Microsoft Acceesibility.

Sendkeys is not reliable either
I will try again tomorrow, but I'm pretty certain the setting didn't stick when I hit the Cancel button.
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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