Print

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
Sub Print_Pages()
Dim TotPages As Long
Dim x As Long
Dim y As Long
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
With ActiveSheet.PageSetup
x = 1
y = Range("AH42").Value
ActiveSheet.PrintOut From:=x, To:=y
End With
End Sub


Gord Dibben MS Excel MVP
 
Private Sub CommandButton1_Click()
Sub Print_Pages()
Dim TotPages As Long
Dim x As Long
Dim y As Long
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
With ActiveSheet.PageSetup
x = 1
y = Range("AH42").Value
ActiveSheet.PrintOut From:=x, To:=y
End With
End Sub

this is what I have but it says compile error expect end sub.
Thanks again
Cheyenne
 
Chey

Delete the line Sub Print_Pages.

You have wrapped my Sub into a CommandButton Sub.


Gord
 
I hope I don't drive you nuts but I actually wanted to add to this.
I want the button on sheet "Request Form"
I want this sheet to print page 1 of 1
and then I want the code you just gave me also
that sheet is called "Attendance Sheet"
I am I able to do all that or do I need to buttons.
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Print Code 1
Date Search 2
If or lookup Statement 2
Enter number in cell and have it divide by 4 10
Count letters 4
2 functions in 1 2
trim 4
Excel Need Countifs Formula Help 0

Back
Top