Print button with default page 1 only print

rapitorres

New Member
Joined
Oct 5, 2017
Messages
39
Office Version
  1. 2010
Platform
  1. Windows
Hi just a simple vba button that will help me print with default page 1 only.

i tried this code

ActiveWindow.SelectedSheets.PrintPreview

it just preview the file and i still need to press print and setup the page.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Option Explicit

Sub PrintFirstPage() 'Excel VBA procedure to printout first page.
Dim sh As Worksheet

For Each sh In Sheets
sh.PrintOut 1, 1, 1, , , , True, , False
Next sh

End Sub
 
Upvote 0
If you wanted to print the first two sheets of each page you would change the code to the following.
sh.PrintOut 1, 2, 1, , , , True, , False
Where 2 is the character to change for the number of sheets to print out. Actually you can change the code to start or end from a different number of sheets. The first part after printout is the start number and the second part is the end number so
sh.PrintOut 5, 10, 1, , , , True, , False
means sheets 5-10 will be printed out.
The attached workbook shows how the Excel VBA procedure works on a sample data set.
 
Upvote 0
hi. thankyou for the response.

im wandering if where to put this code. inside a button? cause i tried it and i got this


Private Sub CommandButton4_Click() << THIS IS HIGHLIGHTED

Sub PrintFirstPage() 'Excel VBA procedure to printout first page.
Dim sh As Worksheet

For Each sh In Sheets
sh.PrintOut 1, 1, 1, , , , True, , False
Next sh

End Sub
 
Upvote 0
thanks alot and sorry.

i studied the code that you provide for me. thanks its working now :)
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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