VBA code to go directly to print settings

oblix

Board Regular
Joined
Mar 29, 2017
Messages
183
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hi there
I would like to create an icon on sheet that when you click on it will do the process of going to file tab and clicking on print to display the page where you set the page to page and print from.
can anybody help with vba code. I could on get the print preview to work, but then requires a nother click to go to settings.
thank you in advance
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this:

VBA Code:
Sub PageSetup()
  Application.Dialogs(xlDialogPageSetup).Show
End Sub
 
Upvote 0
Thank you once again Dante.
But I was looking for printer print page
 
Upvote 0
Or

VBA Code:
 Application.Dialogs(xlDialogPrint).Show
 
Upvote 0
And if you want some action after pressing ok(like printing immediatly), you can use this method

VBA Code:
Sub prnt()
  With Application.Dialogs(xlDialogPrint)
    If .Show Then .......   
  End With
End Sub
 
Upvote 0
Thank you that worked.
If I have cel that shows what page to start printing and cel that shows to what page to print to, can I tell vba to opendialog print and past those values in start and to page or not?
These values can change for everytime I want to print.
If. show Then ........ i was thinking
 
Upvote 0
Then I prefer it like this:

VBA Code:
Sub prnt()
 With ThisWorkbook.Sheets(1)
    .PrintOut .Cells(1, 1), Cells(1, 2)
 End With
End Sub
 
Upvote 0
If I have cel that shows what page to start printing and cel that shows to what page to print to
Try this:

VBA Code:
Sub DialogPrint()
  Dim x As Variant
  x = Application.Dialogs(xlDialogPrint).Show(Arg2:=Range("A1"), Arg3:=Range("A2"))
End Sub
 
Upvote 0
JEC I dont understand sub prnt example.
It gives me an error in printout line.
doesnt printout start printing directly?
I still want to run :
With Application.Dialogs(xlDialogPrint)
If .Show Then......
But want to print pages from to page to be filled from cells i created (sheet PO, cell to start page - b4, cell to last page to print c4.
b4 = 1 c4 = 6 representing page numbers. this changes because it has formulas.
dont know if this makes it more clear
 
Upvote 0
Thank you Dante. Solved my Problem
Thanks also to JEC for effort
Once again gained valuable skills
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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