Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hidden sheets stops macros

Status
Not open for further replies.

vcsinfo

IS-IT--Management
Dec 1, 2005
114
US
I have a spreadsheet with 3 sheets.
Sheet One has the button which then references the other 2 pages to setup a form with several free text fields.
When I hide sheet 2 and 3, I can click on button and open the sheet to fill out several free text fields.
When I hit the print button, I get Runtime error 1004, Printout Method of worksheet failed.
When I unhide the sheets, no errors and I can fill in form and print.
Any way to hide all but sheet one w/o errors.
 
For future reference, VBA/Macro specific questions should be posted in forum707, the VBA Visual Basic for Applications (Microsoft) Forum.

Also, it is always a good idea to provide the code you currently have that is giving you trouble.

All of that having been said,

Code:
ActiveSheet.PrintOut Copies:=1, Collate:=True
should work for you. I imagine that you currently have something like ActiveWorkbook.PrintOut

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
heres what i do have

ActiveWorkbook.Sheets("Sheet3").PrintOut

Sheet 3 is hidden, when hidden I get the error.
I added your line Copies:=1, Collate:=True, did not fix
Maybe cause the ("sheet3") is in there?

oh well its no big deal.

I will also post to forum 7070 next time.Many thnx
 
ActiveWorkbook.Sheets("Sheet3").PrintOut

Sheet 3 is hidden, when hidden I get the error.
Ah! now I see what you're trying to do.

Change the above code to this:
Code:
On Error Resume Next
ActiveWorkbook.Sheets("Sheet3").PrintOut
On Error GoTo 0

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
oooh..well no more errors, but nothing prints. Nothing in print queue either.
I really appreciate the help so far.
 
Ah, so you DO want to print it, even though it is hidden.

Sorry, I hadn't had enough caffeine at that last post....

Is sheet 3 always hidden? Do you always want to hide it after you're done?

No matter. The following code will always leave the sheet in whatever state of "Visibility" it was before you started

Code:
Sub test()
visiblestate = Sheets("sheet3").Visible
    Sheets("sheet3").Visible = True
        Sheets("Sheet3").PrintOut
    Sheets("sheet3").Visible = visiblestate
End Sub

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top