PDA

View Full Version : Macro to open workbook read only



chex
01-15-2009, 07:02 PM
Hello, how do I set the read only attribute when opening a workbook? Please see the code below (does not currently work). :banghead: Thank you!


Private Sub Workbook_Open()
ThisWorkbook.ReadOnly = True
End Sub

lucas
01-15-2009, 08:04 PM
Set wb = Workbooks.Open("f:\Temp\Social Club.xls", True, True)

chex
01-15-2009, 11:07 PM
Should this be copied in the Sub Workbook_Open sub? Thank you.

GTO
01-15-2009, 11:40 PM
chex,

I think you are trying to have the workbook change itself to Read-Only. If this is correct, no real testing, but try:

Private Sub Workbook_Open()
ThisWorkbook.ChangeFileAccess Mode:=xlReadOnly
End Sub

Hope this helps,

Mark

chex
01-16-2009, 02:41 AM
Thank you Mark, that works! Only now it asks me if I want to save the file before changing the status - what can I do to eliminate that prompt? Thank you again.

GTO
01-16-2009, 02:59 AM
Thank you Mark, that works! Only now it asks me if I want to save the file before changing the status - what can I do to eliminate that prompt? Thank you again.

Sorry, I am missing what you are saying. Upon initially adding this to the Open event, I presume it saved okay. After closing - I would also expect the workbook to open w/o anything popping up. What exactly are you saying is happening (and when)?

Mark