Button To Print Workbook With Certain Settings

K

kishan

hi, in a workbook i have 52 numbered sheets. they are
numbered 1, 2, 3, 4 etc. on the first sheet i have two
buttons. i need some coding help with the buttons.
basically i want the first button (called even) to print
all the even sheets in the workbook. and the second
button will print the odd sheets in the workbook. also i
want different margin settings for each button. the even
button will need a left margin of 0.5 and the odd button
will need a right margin of 0.5 - while all the other
margins remain 0.2. i am hoping that this is possible. i
tried recording the marcos but i am not sure how i can
get it to print the evenly and oddly numbered sheets (not
pages). thanks in advance.
 
R

Ron de Bruin

Hi kishan

Left margin : This setting will be saved with the file.
If you want to do it with code post back

Change PrintPreview to PrintOut to print


Sub test1()
Dim shnum As Long
For shnum = 1 To Sheets.Count Step 2
Sheets(shnum).PrintPreview
Next
End Sub

Sub test2()
Dim shnum As Long
For shnum = 2 To Sheets.Count Step 2
Sheets(shnum).PrintPreview
Next
End Sub
 
J

jay

hi, i read this post and i was wondering if i could have
the coding for the margin settings. this is because i
want different margins based on which button is pressed.

eg, when the even button is pressed the margins are:
-- top = 0.5
-- left = 0.2
-- right = 0.5
-- bottom = 0.5

when the odd button is pressed the margins are:
-- top = 0.5
-- left = 0.5
-- right = 0.2
-- bottom = 0.5

thanks agen.

-----Original Message-----
Hi kishan

Left margin : This setting will be saved with the file.
If you want to do it with code post back

Change PrintPreview to PrintOut to print


Sub test1()
Dim shnum As Long
For shnum = 1 To Sheets.Count Step 2
Sheets(shnum).PrintPreview
Next
End Sub

Sub test2()
Dim shnum As Long
For shnum = 2 To Sheets.Count Step 2
Sheets(shnum).PrintPreview
Next
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"kishan" <[email protected]> wrote in
message news:[email protected]...
 
R

Ron de Bruin

Try this Jay

Sub test()
Dim shnum As Long
For shnum = 2 To Sheets.Count Step 2
With Sheets(shnum).PageSetup
.LeftMargin = Application.InchesToPoints(0.2)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
End With
Sheets(shnum).PrintPreview
Next
End Sub
 
Top