Read only - Password entered conditions :)

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
If I code the book to hide sheet1 when I close the sheet, I want the code not to show sheet1 when the workbook is opened in read only mode but show sheet1 only when users enter the book by entering the password.

Not sure if this is possible

Thanks for helping!;)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Maybe this in the ThisWorkbook module

Code:
Private Sub Workbook_Open()
If Me.ReadOnly Then Sheets("Sheet1").Visible = xlSheetVisible
End Sub
 
Upvote 0
I am using it this way...& it does not work...
I mean when I open in read only it does not show sheet1, however when i log in entering the password it does not show sheet1:eek:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
 Sheet1.Visible = xlSheetVeryHidden
End Sub
Private Sub Workbook_Open()
  If Me.ReadOnly Then Sheets("Sheet1").Visible = xlSheetVisible
End Sub
 
Upvote 0
Could be this: in order for the VeryHidden to take effect, you have to save the sheet. But it's read-only, so it can't save. Not sure off the top of my head how to get around that.
 
Upvote 0
Try this instead:
Code:
Private Sub Workbook_Open()
  If ActiveWorkbook.ReadOnly = True Then Sheets("Sheet1").Visible = xlSheetVeryHidden
End Sub

This only acts on the Workbook Open transition, so avoids the "can't save with sheet VeryHidden while workbook is read-only" issue. Also, the decision to hide or not hide was written backwards (if read-only, then visible should be NO, not YES)

The code above works in my test on Excel 2003, no idea about '07 or '10
 
Last edited:
Upvote 0
Vog, if you're still around please advice again.
I tried by hiding the sheet first then opening in read only....I also tried by keeping sheet1 visible but still code does not impact the sheet from staying hidden even when i enter in read only mode....
Code:
Private Sub Workbook_Open()
  If Me.ReadOnly Then Sheets("Sheet1").Visible = xlSheetVisible
End Sub
Code:
I also tried this way...but does not hide sheet1 when i open in read only mode....if you guys have some idea bout this pls help!!!
Private Sub Workbook_Open()
  If Me.ReadOnly Then Sheets("Sheet1").Visible = False
  
End Sub
 
Last edited:
Upvote 0
Gardnertoo, thank you so much! this worked perfectly. I think we cross posted I didn't recognize it untill Brian commented on ur code!

Thanks Brain, once again thank you Gardnertoo!

Hey Vog! thanks to you too!

Have a GREAT Weekend guys!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,217,441
Messages
6,136,655
Members
450,022
Latest member
Joel1122331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top