Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 - |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I print a workbook in but only print selected worksheets? | Excel Discussion (Misc queries) | |||
Active cell counting in particular print page (one sheet having different print area) | Excel Worksheet Functions | |||
Why do I get a print error light trying to print an excel sheet ? | Excel Discussion (Misc queries) | |||
Macro to open print window and set to print entire workbook | Excel Discussion (Misc queries) | |||
How can I print page 2 of each sheet in a workbook? | Excel Discussion (Misc queries) |