View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 292
Default Workbook close error

It's a distinct limitation for xls files: At least one sheet must be
visible. So you can't hide all and then show one. Modify to something like

ThisWorkbook.Sheets("Welcome").visible = true
For Each ws In ThisWorkbook.Worksheets
if ws.name < "Welcome" then ws.Visible = xlVeryHidden
Next ws

Note also that the workbook must be unprotected before you change sheet
visibility.

HTH. best wishes Harald

"Rich" skrev i melding
m...
I have the following code, that produces an error 400 when the macro
sub routine is run by itself. What I want it to do, is out a number of
sheets in a workbook, when the workbook closes, all sheets will be
veryhidden except one called "Welcome". As you can probably tell, I am
trying to make use of the 'force macros' style of hiding important
sheets before macros are enabled. If macros are disabled, then the
only sheet visible will "Welcome"

-----------------------------------------
Sub workbook_before_close()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlVeryHidden
Next ws
Call Show_Welcome
Application.SaveWorkspace
End Sub
-----------------------------------------

What is the problem with what I have typed? Is there a better way of
hiding a range of sheets that are not called Welcome?
All comments are welcomed (as is any replacement code!)