Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Workbook open code to do 2 things

Hi,

I originally had the following in ThisWorkbook

Private Sub Workbook_Open()
Dim sht As Worksheet
Const TopLeft As String = "a2"
Application.ScreenUpdating = False
For Each sht In Worksheets
Application.Goto sht.Range(TopLeft), Scroll:=True
sht.Protect Password:="*gwb", _
UserInterFaceOnly:=True
Next sht

Application.ScreenUpdating = True
Sheets("Sheet1").Select

Now I'm trying to make users enable macros by hiding sheets.

Sheets("Sheet1").Visible = True
Sheets("Warning").Visible = xlVeryHidden
Sheets("STEP 1").Visible = True

and so on for approx twenty sheets before the For each bit. I was intending
to make an array of sheets that I can make visible but I can't get both bits
of the macro working at the same time as I get a runtime error.

Is it because I also have some sheets in the workbook that are hidden
normally or because of the very hidden sheet?

Any ideas on what I need to do would be brilliant!

Cheers










  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Workbook open code to do 2 things

Try putting your Sheet visibility stuff after the For each sheet loop.

You could also use a select case within the For each sheet loop like this
Select Case sht.Name
Case "Sheet1", "Step 1"
sht.Visible=True
Case "Warning"
sht.Visible = xlVeryHidden
End Select

If most sheets are visible and stay that way you could shorten it up even
more like this (and not have to type each sheet name

Select Case sht.Name
Case "Warning"
sht.Visible = xlVeryHidden
Case Else
sht.Visible=True
End Select




--
If this helps, please remember to click yes.


"Diddy" wrote:

Hi,

I originally had the following in ThisWorkbook

Private Sub Workbook_Open()
Dim sht As Worksheet
Const TopLeft As String = "a2"
Application.ScreenUpdating = False
For Each sht In Worksheets
Application.Goto sht.Range(TopLeft), Scroll:=True
sht.Protect Password:="*gwb", _
UserInterFaceOnly:=True
Next sht

Application.ScreenUpdating = True
Sheets("Sheet1").Select

Now I'm trying to make users enable macros by hiding sheets.

Sheets("Sheet1").Visible = True
Sheets("Warning").Visible = xlVeryHidden
Sheets("STEP 1").Visible = True

and so on for approx twenty sheets before the For each bit. I was intending
to make an array of sheets that I can make visible but I can't get both bits
of the macro working at the same time as I get a runtime error.

Is it because I also have some sheets in the workbook that are hidden
normally or because of the very hidden sheet?

Any ideas on what I need to do would be brilliant!

Cheers










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
one code to do multiple things Morgan New Users to Excel 0 February 24th 10 07:09 AM
how can i open a second workbook using a vba code [email protected] uk Excel Discussion (Misc queries) 10 November 28th 09 05:42 PM
Set certain things when opening the Workbook JoAnn New Users to Excel 4 February 28th 08 05:50 PM
Need VB code for workbook open to open a link Daniel Baker Excel Discussion (Misc queries) 2 August 18th 06 01:30 AM
Help!!!! Strange things are happening to a Shared Workbook!! Sarahp Excel Worksheet Functions 0 February 6th 06 01:05 PM


All times are GMT +1. The time now is 04:22 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"