Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Print only 1 sheet in a workbook.

I have a workbook with sheets numbered 1 to 20. On another sheet I
have a print button. I need to have the print button work so that it
prints just 1 of those 20 sheets. The sheet number to be printed will
be in a cell on sheet Data3, Cell:C7.

The print button is on another sheet.

I'm at a loss to write a macro that can do this job.
Can anyone help?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Print only 1 sheet in a workbook.

Sub PrintCopies()
Dim whichone as Long
whichone = Sheets("Data3").Range("C7").Value
Sheets(whichone).PrintOut
End Sub


Gord Dibben MS Excel MVP

On 17 Feb 2007 17:31:54 -0800, wrote:

I have a workbook with sheets numbered 1 to 20. On another sheet I
have a print button. I need to have the print button work so that it
prints just 1 of those 20 sheets. The sheet number to be printed will
be in a cell on sheet Data3, Cell:C7.

The print button is on another sheet.

I'm at a loss to write a macro that can do this job.
Can anyone help?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Print only 1 sheet in a workbook.

Option Explicit
Sub PrintMe()
dim wks as worksheet
set wks = nothing
on error resume next
set wks = worksheets("Data3").range("C7").value
on error goto 0

if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm



wrote:

I have a workbook with sheets numbered 1 to 20. On another sheet I
have a print button. I need to have the print button work so that it
prints just 1 of those 20 sheets. The sheet number to be printed will
be in a cell on sheet Data3, Cell:C7.

The print button is on another sheet.

I'm at a loss to write a macro that can do this job.
Can anyone help?

Thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Print only 1 sheet in a workbook.

There could be a bug in both Gord's code and mine.

If there's a number in that cell, then you'll want to make sure that you're
printing the sheet named 3--not the 3rd sheet from the left.

Gord's code would change to this:

Sub PrintCopies()
Dim whichone as Long
whichone = Sheets("Data3").Range("C7").Value
Sheets(cstr(whichone)).PrintOut
End Sub


And I assumed that they were worksheets. They could be chart sheets. My code
should be changed to this:

Option Explicit
Sub PrintMe()
dim wks as Object
set wks = nothing
on error resume next
set wks = sheets(cstr(worksheets("Data3").range("C7").value) )
on error goto 0

if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub

This line was also wrong in my original suggestion:

set wks = worksheets("Data3").range("C7").value
It should have been:
set wks = worksheets(worksheets("Data3").range("C7").value)
but the cstr() function should have been used, too:
set wks = worksheets(cstr(worksheets("Data3").range("C7").va lue))

Dave Peterson wrote:

Option Explicit
Sub PrintMe()
dim wks as worksheet
set wks = nothing
on error resume next
set wks = worksheets("Data3").range("C7").value
on error goto 0

if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

wrote:

I have a workbook with sheets numbered 1 to 20. On another sheet I
have a print button. I need to have the print button work so that it
prints just 1 of those 20 sheets. The sheet number to be printed will
be in a cell on sheet Data3, Cell:C7.

The print button is on another sheet.

I'm at a loss to write a macro that can do this job.
Can anyone help?

Thanks


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Print only 1 sheet in a workbook.

Thanks muchly to both yourself and Gord. I tried Gords suggestion
first and it does exactly what I needed.
I appreciate the time and effort of you both.

Cheers


On Feb 18, 12:07 pm, Dave Peterson wrote:
There could be a bug in both Gord's code and mine.

If there's a number in that cell, then you'll want to make sure that you're
printing the sheet named 3--not the 3rd sheet from the left.

Gord's code would change to this:

Sub PrintCopies()
Dim whichone as Long
whichone = Sheets("Data3").Range("C7").Value
Sheets(cstr(whichone)).PrintOut
End Sub

And I assumed that they were worksheets. They could be chart sheets. My code
should be changed to this:

Option Explicit
Sub PrintMe()
dim wks as Object
set wks = nothing
on error resume next
set wks = sheets(cstr(worksheets("Data3").range("C7").value) )
on error goto 0

if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub

This line was also wrong in my original suggestion:

set wks = worksheets("Data3").range("C7").value
It should have been:
set wks = worksheets(worksheets("Data3").range("C7").value)
but the cstr() function should have been used, too:
set wks = worksheets(cstr(worksheets("Data3").range("C7").va lue))





Dave Peterson wrote:

Option Explicit
Sub PrintMe()
dim wks as worksheet
set wks = nothing
on error resume next
set wks = worksheets("Data3").range("C7").value
on error goto 0


if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


wrote:


I have a workbook with sheets numbered 1 to 20. On another sheet I
have a print button. I need to have the print button work so that it
prints just 1 of those 20 sheets. The sheet number to be printed will
be in a cell on sheet Data3, Cell:C7.


The print button is on another sheet.


I'm at a loss to write a macro that can do this job.
Can anyone help?


Thanks


--


Dave Peterson


--

Dave Peterson- Hide quoted text -

- Show quoted text -





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Print only 1 sheet in a workbook.

Update...
It worked fine until I hid all the sheets named 1 to 20.
Can I get it to work with those sheets hidden?


On Feb 18, 2:15 pm, wrote:
Thanks muchly to both yourself and Gord. I tried Gords suggestion
first and it does exactly what I needed.
I appreciate the time and effort of you both.

Cheers

On Feb 18, 12:07 pm, Dave Peterson wrote:

There could be a bug in both Gord's code and mine.


If there's a number in that cell, then you'll want to make sure that you're
printing the sheet named 3--not the 3rd sheet from the left.


Gord's code would change to this:


Sub PrintCopies()
Dim whichone as Long
whichone = Sheets("Data3").Range("C7").Value
Sheets(cstr(whichone)).PrintOut
End Sub


And I assumed that they were worksheets. They could be chart sheets. My code
should be changed to this:


Option Explicit
Sub PrintMe()
dim wks as Object
set wks = nothing
on error resume next
set wks = sheets(cstr(worksheets("Data3").range("C7").value) )
on error goto 0


if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub


This line was also wrong in my original suggestion:


set wks = worksheets("Data3").range("C7").value
It should have been:
set wks = worksheets(worksheets("Data3").range("C7").value)
but the cstr() function should have been used, too:
set wks = worksheets(cstr(worksheets("Data3").range("C7").va lue))


Dave Peterson wrote:


Option Explicit
Sub PrintMe()
dim wks as worksheet
set wks = nothing
on error resume next
set wks = worksheets("Data3").range("C7").value
on error goto 0


if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


wrote:


I have a workbook with sheets numbered 1 to 20. On another sheet I
have a print button. I need to have the print button work so that it
prints just 1 of those 20 sheets. The sheet number to be printed will
be in a cell on sheet Data3, Cell:C7.


The print button is on another sheet.


I'm at a loss to write a macro that can do this job.
Can anyone help?


Thanks


--


Dave Peterson


--


Dave Peterson- Hide quoted text -


- Show quoted text -



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Print only 1 sheet in a workbook.

Save the current state.
make it visible (if it isn't)
print it
set it back to that original state


Sub PrintCopies()
Dim whichone as String
Dim IsVisible as long
whichone = cstr(Sheets("Data3").Range("C7").Value)
isVisible = sheets(whichone).visible
sheets(whichone).visible = xlsheetvisible
Sheets(whichone).PrintOut
sheets(whichone).visible = isvisible
End Sub

One of the differences between the code I posted and the code Gord posted was
what'll happen when you have a typo in C7.

wrote:

Update...
It worked fine until I hid all the sheets named 1 to 20.
Can I get it to work with those sheets hidden?

On Feb 18, 2:15 pm, wrote:
Thanks muchly to both yourself and Gord. I tried Gords suggestion
first and it does exactly what I needed.
I appreciate the time and effort of you both.

Cheers

On Feb 18, 12:07 pm, Dave Peterson wrote:

There could be a bug in both Gord's code and mine.


If there's a number in that cell, then you'll want to make sure that you're
printing the sheet named 3--not the 3rd sheet from the left.


Gord's code would change to this:


Sub PrintCopies()
Dim whichone as Long
whichone = Sheets("Data3").Range("C7").Value
Sheets(cstr(whichone)).PrintOut
End Sub


And I assumed that they were worksheets. They could be chart sheets. My code
should be changed to this:


Option Explicit
Sub PrintMe()
dim wks as Object
set wks = nothing
on error resume next
set wks = sheets(cstr(worksheets("Data3").range("C7").value) )
on error goto 0


if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub


This line was also wrong in my original suggestion:


set wks = worksheets("Data3").range("C7").value
It should have been:
set wks = worksheets(worksheets("Data3").range("C7").value)
but the cstr() function should have been used, too:
set wks = worksheets(cstr(worksheets("Data3").range("C7").va lue))


Dave Peterson wrote:


Option Explicit
Sub PrintMe()
dim wks as worksheet
set wks = nothing
on error resume next
set wks = worksheets("Data3").range("C7").value
on error goto 0


if wks is nothing then
msgbox "Not a worksheet name in C7 of Data3"
else
wks.printout preview:=true
end if
end sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

wrote:


I have a workbook with sheets numbered 1 to 20. On another sheet I
have a print button. I need to have the print button work so that it
prints just 1 of those 20 sheets. The sheet number to be printed will
be in a cell on sheet Data3, Cell:C7.


The print button is on another sheet.


I'm at a loss to write a macro that can do this job.
Can anyone help?


Thanks


--


Dave Peterson


--


Dave Peterson- Hide quoted text -


- Show quoted text -


--

Dave Peterson
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
How do I print a workbook in but only print selected worksheets? Karl S. Excel Discussion (Misc queries) 1 August 31st 06 12:34 AM
Active cell counting in particular print page (one sheet having different print area) ananthmca2004 Excel Worksheet Functions 1 November 24th 05 11:29 AM
Why do I get a print error light trying to print an excel sheet ? SMC Excel Discussion (Misc queries) 2 November 5th 05 01:36 AM
Macro to open print window and set to print entire workbook retseort Excel Discussion (Misc queries) 1 October 27th 05 11:00 PM
How can I print page 2 of each sheet in a workbook? sflower Excel Discussion (Misc queries) 1 March 9th 05 02:15 PM


All times are GMT +1. The time now is 04:21 AM.

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

About Us

"It's about Microsoft Excel"