Read Only

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good day. I have an Excel file that I want to give the users an option of
opening Read Only or open for edit. I don't want to do this through a
desktop shortcut, but rather through VBA. Is there any VBA code that will
allow this, or can I make a file read only once it is opened using
"ReadOnly:=True" or something of that nature.

Thanks,
 
Maybe you could do this:

Save your file with "readonly recommended" checked.

File|SaveAs|tools|general options|check that "read-only recommended" box.

Then the user will be prompted each time they open it.

====
If you really want VBA (I wouldn't!) since macros can be disabled. You could
ask after the workbook is opened.

Option Explicit
Sub auto_open()

Dim resp As Long
If ThisWorkbook.ReadOnly = True Then
'they opened it readonly
'do nothing
Else
resp = MsgBox(Prompt:="What to change it to readonly?", _
Buttons:=vbYesNo)

If resp = vbYes Then
ThisWorkbook.ChangeFileAccess xlReadOnly
End If
End If

End Sub
 
Thank you Dave, just what I needed.


Dave Peterson said:
Maybe you could do this:

Save your file with "readonly recommended" checked.

File|SaveAs|tools|general options|check that "read-only recommended" box.

Then the user will be prompted each time they open it.

====
If you really want VBA (I wouldn't!) since macros can be disabled. You could
ask after the workbook is opened.

Option Explicit
Sub auto_open()

Dim resp As Long
If ThisWorkbook.ReadOnly = True Then
'they opened it readonly
'do nothing
Else
resp = MsgBox(Prompt:="What to change it to readonly?", _
Buttons:=vbYesNo)

If resp = vbYes Then
ThisWorkbook.ChangeFileAccess xlReadOnly
End If
End If

End Sub
 

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

Back
Top