Print

C

Chey

I want to put a command button on my excel spreadsheet. I have how many
pages in a cell example in cell AH42 will say 3. How do I tell it to print
pages 1-(whatever the number in AH42) is?
Thanks
Cheyenne
 
D

Dave Peterson

Something like:

Option Explicit
Sub testme()
With ActiveSheet
.PrintOut from:=1, to:=.Range("ah42").Value, preview:=True
End With
End Sub

You may want to verify that that range holds a nice valid number, too.
 
G

Gord Dibben

You could do it all in one macro or two separate macros.

Here is a single macro that prints page 1 of 1 from Request Form then prints the
number of pages found in AH42 on Attendance Sheet.

Please forgive the "selects". Too busy to correct right now.

Private Sub CommandButton1_Click()
Dim TotPages As Long
Dim x As Long
Dim y As Long

TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
Sheets("Request Form").Select
With ActiveSheet.PageSetup
ActiveSheet.PrintOut From:=1, To:=1
End With
Sheets("Attendance Sheet").Select
With ActiveSheet.PageSetup
x = 1
y = Range("AH42").Value
ActiveSheet.PrintOut From:=x, To:=y
End With
End Sub


Gord
 
C

Chey

So far so good except
ActiveSheet.PrintOut From:=X, To:=y
It says is has to be between 1 and some large number.
Thanks for your time.
 
G

Gord Dibben

I do not get this message when I test the code.

Maybe change Long to Integer.


Gord
 
Top