Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Hide Sheets when closing file

Hi...

Is there code that will allow me to hide all sheets except sheet1 when I
close my file. Equally, when opening the file and macros are enabled is there
code that can make all sheets visible but sheet 1 invisible?

Many thanks

Gordon...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Hide Sheets when closing file

Hi Gordon,

These should do you; they go in the 'ThisWorkbook' module.

Option Explicit
Private Sub Workbook_Open()
Dim Wks As Object
Application.ScreenUpdating = False
For Each Wks In Sheets
Wks.Visible = True
If Wks.Name = "Sheet1" Then Wks.Visible = xlSheetHidden
Next Wks
Application.ScreenUpdating = True
End Sub
----------------------------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Wks As Object
For Each Wks In Sheets
If Not Wks.Name = "Sheet1" Then Wks.Visible = xlSheetHidden
Next Wks
ActiveWorkbook.Save
End Sub

Cheers,
JF.

On 29 Sep, 07:24, Gordon wrote:
Hi...

Is there code that will allow me to hide all sheets except sheet1 when I
close my file. Equally, when opening the file and macros are enabled is there
code that can make all sheets visible but sheet 1 invisible?

Many thanks

Gordon...


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Hide Sheets when closing file

Stunning...thanks. This is about the 10th post on this and I was tearing my
hair out.

Thanks again

G

" wrote:

Hi Gordon,

These should do you; they go in the 'ThisWorkbook' module.

Option Explicit
Private Sub Workbook_Open()
Dim Wks As Object
Application.ScreenUpdating = False
For Each Wks In Sheets
Wks.Visible = True
If Wks.Name = "Sheet1" Then Wks.Visible = xlSheetHidden
Next Wks
Application.ScreenUpdating = True
End Sub
----------------------------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Wks As Object
For Each Wks In Sheets
If Not Wks.Name = "Sheet1" Then Wks.Visible = xlSheetHidden
Next Wks
ActiveWorkbook.Save
End Sub

Cheers,
JF.

On 29 Sep, 07:24, Gordon wrote:
Hi...

Is there code that will allow me to hide all sheets except sheet1 when I
close my file. Equally, when opening the file and macros are enabled is there
code that can make all sheets visible but sheet 1 invisible?

Many thanks

Gordon...



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
Excel sheets closing on their own LaurenM Excel Discussion (Misc queries) 0 May 16th 08 02:24 PM
hide personal.xlsb file without closing Terry Excel Discussion (Misc queries) 3 July 21st 07 07:08 AM
Closing sheets and selecting 'no' automatically Graham Whitehead Excel Programming 4 July 19th 06 04:50 PM
Hide specific sheets on closing file Andy Excel Programming 1 June 19th 06 01:23 PM
How Can I hide sheets when closing the app? jose luis Excel Programming 1 September 14th 04 10:59 PM


All times are GMT +1. The time now is 04:14 AM.

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

About Us

"It's about Microsoft Excel"