Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Workbook close error

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!)
  #2   Report Post  
Posted to microsoft.public.excel.programming
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!)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Workbook close error

Hi Rich,

You cannot have all sheets hidden. so your code bombs on trying to hide the
last one, before the call to show the Welcome sheet

Try this amendment

Sub workbook_before_close()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = (ws.Name < "Welcome") * -1 - 1
Next ws
Application.SaveWorkspace
End Sub

--

HTH

RP

"Rich" wrote in message
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!)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Workbook close error

This will err if Welcome is the last sheet. (But it probably isn't :-)

Best wishes Harald

"Bob Phillips" skrev i melding
...

Sub workbook_before_close()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = (ws.Name < "Welcome") * -1 - 1
Next ws
Application.SaveWorkspace
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Workbook close error

It didn't for me Harald, I tested with Welcome as the last sheet.

--

HTH

RP

"Harald Staff" wrote in message
...
This will err if Welcome is the last sheet. (But it probably isn't :-)

Best wishes Harald

"Bob Phillips" skrev i melding
...

Sub workbook_before_close()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = (ws.Name < "Welcome") * -1 - 1
Next ws
Application.SaveWorkspace
End Sub







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Workbook close error

Then it was either not last from the collection point of view, or already
visible, or you have a visible chart sheet or similar besides the
worksheets. "You need macros enabled" sheets are often hidden after the code
unhid the others.

Sub test()
Dim S As String, WS As Worksheet
S = Worksheets(Worksheets.Count).Name
Worksheets(S).Visible = xlVeryHidden
For Each WS In ThisWorkbook.Worksheets
WS.Visible = (WS.Name < S) * -1 - 1
Next WS
End Sub

But as stated; probably no big deal.

Best wishes Harald

"Bob Phillips" skrev i melding
...
It didn't for me Harald, I tested with Welcome as the last sheet.

--

HTH

RP

"Harald Staff" wrote in message
...
This will err if Welcome is the last sheet. (But it probably isn't :-)

Best wishes Harald

"Bob Phillips" skrev i melding
...

Sub workbook_before_close()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = (ws.Name < "Welcome") * -1 - 1
Next ws
Application.SaveWorkspace
End Sub







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Workbook close error

Yes it was already visible, but I don't recall seeing anything from the OP
that it wouldn't be.

--

HTH

RP

"Harald Staff" wrote in message
...
Then it was either not last from the collection point of view, or already
visible, or you have a visible chart sheet or similar besides the
worksheets. "You need macros enabled" sheets are often hidden after the

code
unhid the others.

Sub test()
Dim S As String, WS As Worksheet
S = Worksheets(Worksheets.Count).Name
Worksheets(S).Visible = xlVeryHidden
For Each WS In ThisWorkbook.Worksheets
WS.Visible = (WS.Name < S) * -1 - 1
Next WS
End Sub

But as stated; probably no big deal.

Best wishes Harald

"Bob Phillips" skrev i melding
...
It didn't for me Harald, I tested with Welcome as the last sheet.

--

HTH

RP

"Harald Staff" wrote in message
...
This will err if Welcome is the last sheet. (But it probably isn't :-)

Best wishes Harald

"Bob Phillips" skrev i melding
...

Sub workbook_before_close()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = (ws.Name < "Welcome") * -1 - 1
Next ws
Application.SaveWorkspace
End Sub








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Workbook close error

OP said "What is the problem with what I have typed?"; we should consider
everything and assume nothing.

HTH. Best wishes Harald

"Bob Phillips" skrev i melding
...
Yes it was already visible, but I don't recall seeing anything from the OP
that it wouldn't be.

--

HTH

RP

"Harald Staff" wrote in message
...
Then it was either not last from the collection point of view, or

already
visible, or you have a visible chart sheet or similar besides the
worksheets. "You need macros enabled" sheets are often hidden after the

code
unhid the others.




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
run-time error '91'-Close Button error ASCO IS Help Excel Discussion (Misc queries) 1 May 8th 06 04:25 PM
commandbar at workbook before close - run time error tango Excel Programming 1 October 24th 04 10:42 PM
commandbar at workbook before close - run time error tango Excel Programming 1 October 23rd 04 08:26 AM
Close a the current workbook and load another specified workbook Adrian[_7_] Excel Programming 4 August 7th 04 05:29 PM
When running workbook.close True Excel generates an error!!! Daniel[_10_] Excel Programming 2 May 11th 04 05:31 PM


All times are GMT +1. The time now is 11:34 AM.

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

About Us

"It's about Microsoft Excel"