Saving a file within a macro but only when it does not have a read only attribute

A

Alex

I have a spreadsheet that is updated overnight and is then available for
multiple users to see. The approach I am taking is this (I make no
apologies for the fact there are probably a hundred better approaches to the
one I am taking!!):

1. Run a DOS batch job that removes the read only attribute from the Excel
file
2. Open the Excel file as a scheduled task.
3. The Excel file has an auto_open macro that updates some values and saves
itself before closing
4. Run a DOS batch job that reapplies the read only attribute from the Excel
file

I am applying the read only attribute to allow multiple users to view the
file without getting the notification message that someone is already
accessing it. However, when the users open the file, it starts the
Auto_open macro which in turn tries to save the file, but of course fails
because the Read Only attribute is applied.

How do I get the macro to only run if the file is not read only?

Alternatively, if there are any better ways of achieving the above in a more
sophisticated way, I'm all ears!

Thanks in advance
Alex
 
T

Tom Ogilvy

Public Sub Auto_Open()
if not ThisWorkbook.ReadOnly then

' existing code goes here
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

Top