#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default Print

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Print

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.

Chey wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Print

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

On Wed, 11 Apr 2007 11:34:02 -0700, Chey wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default Print

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

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 11:34:02 -0700, Chey wrote:

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



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Print

Chey

Delete the line Sub Print_Pages.

You have wrapped my Sub into a CommandButton Sub.


Gord

On Wed, 11 Apr 2007 13:16:02 -0700, Chey wrote:

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

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 11:34:02 -0700, Chey wrote:

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






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default Print

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.

"Gord Dibben" wrote:

Chey

Delete the line Sub Print_Pages.

You have wrapped my Sub into a CommandButton Sub.


Gord

On Wed, 11 Apr 2007 13:16:02 -0700, Chey wrote:

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

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 11:34:02 -0700, Chey wrote:

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




  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Print

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

On Wed, 11 Apr 2007 15:32:02 -0700, Chey wrote:

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.

"Gord Dibben" wrote:

Chey

Delete the line Sub Print_Pages.

You have wrapped my Sub into a CommandButton Sub.


Gord

On Wed, 11 Apr 2007 13:16:02 -0700, Chey wrote:

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

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 11:34:02 -0700, Chey wrote:

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





  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default Print

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.

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 15:32:02 -0700, Chey wrote:

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.

"Gord Dibben" wrote:

Chey

Delete the line Sub Print_Pages.

You have wrapped my Sub into a CommandButton Sub.


Gord

On Wed, 11 Apr 2007 13:16:02 -0700, Chey wrote:

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

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 11:34:02 -0700, Chey wrote:

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






  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Print

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

Maybe change Long to Integer.


Gord


On Wed, 11 Apr 2007 17:12:02 -0700, Chey wrote:

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.

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 15:32:02 -0700, Chey wrote:

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.

"Gord Dibben" wrote:

Chey

Delete the line Sub Print_Pages.

You have wrapped my Sub into a CommandButton Sub.


Gord

On Wed, 11 Apr 2007 13:16:02 -0700, Chey wrote:

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

"Gord Dibben" wrote:

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

On Wed, 11 Apr 2007 11:34:02 -0700, Chey wrote:

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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print and Print Preview Graphic Moving Resizing 2007/2003 Adam Rayburn Excel Discussion (Misc queries) 0 April 4th 07 04:18 PM
cell borders that I create dont show on print preview or print scott3435 Excel Discussion (Misc queries) 2 April 6th 06 02:37 AM
Pivot Table macro to set print area and print details of drill down data Steve Haskins Excel Discussion (Misc queries) 2 December 28th 05 04:59 PM
Active cell counting in particular print page (one sheet having different print area) ananthmca2004 Excel Worksheet Functions 1 November 24th 05 11:29 AM
How can I print current row in same place on paper but not print surrounding cells??? Andy Ford New Users to Excel 1 September 2nd 05 05:50 AM


All times are GMT +1. The time now is 02:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"