Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.officedev,microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Generic VB Code to Hide Spreadsheet

Is there a generic VB code that will hide all spreadsheets in a workbook but
one. I use this method to prevent users from using the file after disabling
macros. If they Disable Macros, all they see is a spreadsheet with a message
saying 'to use this file they have to Enable Macros'. When Macros are enable
and the file is closed/saved, all sheets, except the one with the message,
are made invisible and the workbook protected (locked), and when the file is
opened with Macros Enabled all sheets except the one with message are made
visible and the workbook is unlocked (not protected).

The problem is that a user can add a new spreadsheet to the workbook and the
code I use will not make the new spreadsheet invisible on closing. The code
I use is:

sheets("Sheet Name").visible=false

Is there a way to make all sheets invisible or a toggle command to reverse
the existing visible property for all sheets in a workbook? Or perhaps,
there is a better approach. Any assistance will be appreciated.
  #2   Report Post  
Posted to microsoft.public.officedev,microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Generic VB Code to Hide Spreadsheet

Try something like

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
If WS.Name < "SheetNotToHide" Then
WS.Visible = xlSheetVeryHidden ' xlSheetVisible to make
visible
End If
Next WS


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"JR_06062005" wrote in
message
...
Is there a generic VB code that will hide all spreadsheets in a
workbook but
one. I use this method to prevent users from using the file
after disabling
macros. If they Disable Macros, all they see is a spreadsheet
with a message
saying 'to use this file they have to Enable Macros'. When
Macros are enable
and the file is closed/saved, all sheets, except the one with
the message,
are made invisible and the workbook protected (locked), and
when the file is
opened with Macros Enabled all sheets except the one with
message are made
visible and the workbook is unlocked (not protected).

The problem is that a user can add a new spreadsheet to the
workbook and the
code I use will not make the new spreadsheet invisible on
closing. The code
I use is:

sheets("Sheet Name").visible=false

Is there a way to make all sheets invisible or a toggle command
to reverse
the existing visible property for all sheets in a workbook? Or
perhaps,
there is a better approach. Any assistance will be
appreciated.



  #3   Report Post  
Posted to microsoft.public.officedev,microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Generic VB Code to Hide Spreadsheet

Sheets("Enabler Sheet").Visible = xlSheetVisible
For Each sh In Activeworkbook.Sheets
If sh.Name < "Enabler Sheet" Then
sh.visible = xlSheetVeryHidden
End If
Next For

Just do it in reverse on startup.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"JR_06062005" wrote in message
...
Is there a generic VB code that will hide all spreadsheets in a workbook

but
one. I use this method to prevent users from using the file after

disabling
macros. If they Disable Macros, all they see is a spreadsheet with a

message
saying 'to use this file they have to Enable Macros'. When Macros are

enable
and the file is closed/saved, all sheets, except the one with the message,
are made invisible and the workbook protected (locked), and when the file

is
opened with Macros Enabled all sheets except the one with message are made
visible and the workbook is unlocked (not protected).

The problem is that a user can add a new spreadsheet to the workbook and

the
code I use will not make the new spreadsheet invisible on closing. The

code
I use is:

sheets("Sheet Name").visible=false

Is there a way to make all sheets invisible or a toggle command to reverse
the existing visible property for all sheets in a workbook? Or perhaps,
there is a better approach. Any assistance will be appreciated.



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
Want to Hide columns in spreadsheet but NOT hide data in chart. KrispyData Charts and Charting in Excel 1 March 20th 09 04:45 PM
Change a specific code to generic in VB macro Sue Excel Discussion (Misc queries) 2 April 23rd 08 06:56 PM
Connecting an excel spreadsheet to a generic letter in Word Christine Excel Discussion (Misc queries) 2 December 6th 06 10:20 PM
Generic protect/unprotect code through buttons and code? StargateFanFromWork[_3_] Excel Programming 4 December 31st 05 12:10 AM
VBA Code- Copy and paste into a generic text box Bourbon[_18_] Excel Programming 0 January 23rd 04 02:42 PM


All times are GMT +1. The time now is 11:59 PM.

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"