PDA

View Full Version : VBA code to open an Excel workbook readonly



Beatrix
07-15-2010, 07:54 AM
Dear All ,

I want to use a VBA code to open an excel workbook as readonly. I've found a code which is working but it doesn't run when I open the workbook, I open the workbook and run the macro then it makes it readonly..Do you have any idea how can I get it to run as soon as the spreadsheet is opened.

Sub OpenReadonly()
Workbooks.Open fileName:="U:\MIS\test.xls", ReadOnly:=True
End Sub

your help would be much appreciated..

Regards,
Yeliz

Bob Phillips
07-15-2010, 08:14 AM
Your post doesn't make sense. The code you gave should open the workbook as a read-only workbook.

Your code won't make a workbook read-only after it has been opened, it can be done, but not that way.

Beatrix
07-15-2010, 08:52 AM
Hi ,

Thank you very much for your reply..I don't know too much about VBA. I have a spreadsheet with lots of macros and I added this code to "This Workbook" part and saved it, when I open the spreadsheet it's not read only but I can see it in macro windows and I run it and it becomes readonly.. :(

Bob Phillips
07-15-2010, 10:42 AM
Okay, let's take a step back and check what you are trying to do.

Are you either trying to open ANOTHER workbook from within your code and open it read-only,

OR

are you trying to ensure that when you open a particular workbook THAT book is opened read-only.

Aussiebear
07-15-2010, 02:18 PM
From my reading of the thread Bob,the OP wants the second option... so as soon as the User opens the workbook its status is read only

Bob Phillips
07-15-2010, 03:06 PM
That is my assumption also Ted, but not what he said at the start, so I would like to hear from the OP.