Code based on opening Read Only or not

C

Craig

Hi

When a user opens my file they see the standard password box in which they
can either click the Read Only button and work in it as Read Only or enter
the password and work in it with write access.

Is there macro code I can enter in the same file that would hide a group of
worksheets if the user opens that file with write access but would not hide
these worksheets if they open the file as Read only?

thank you very much.....Craig
 
D

Dave Peterson

You could use the Auto_Open() procedure in a General module:

Option Explicit
Sub auto_open()
If ThisWorkbook.ReadOnly Then
'do what you want
Else
'do something else
End If
End Sub

Or the Workbook_Open() event in the ThisWorkbook:

Option Explicit
Sub Workbook_Open()
If Me.ReadOnly Then
'do what you want
Else
'do something else
End If
End Sub
 
B

Barb Reinhardt

If you are referring to your opened workbook as oWB, use something like this

if oWB.ReadOnly then
'Do read only stuff
else
'Do edit stuff
End if

HTH,
Barb Reinhardt
 
R

Rick Rothstein

I guess the OP could start the workbook with the group of sheets hidden and
the workbook password protected. Then, when the workbook is opened, he could
check to see if it is read-only or not... if it is not read only, he could
unhide those sheets. When the workbook is closed, he could re-hide the
sheets and re-apply the password protection. I guess to stop anyone from
discovering the embedded password, he would have to come up with an
encryption/decryption algorithm to make it harder to figure out what the
password is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top