View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
[email protected] boonarga@gmail.com is offline
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 -