You are here:

Excel/VBA and read write access


I am not too sure on how to word this; I have two files as primary and secondary.  The secondary, which is not open, is saved with two passwords, one to open as read only and another for write access.  When the primary file is activated via VBA the auto open macro will open the secondary file as a read only and update the primary file then close the secondary file.  The user will input new data into the primary file and when the user exits the primary file the “BeforeClose” macro will activate.  This time the macro will open the secondary file as “write access” and save the updated data from the primary to the secondary file.  
All of this works fine except when the secondary file is currently open by another user. Since it is not possible to have the same file open twice in write access mode at the same time, when this happens I want the macro to close the secondary file (because in this case it will be a read only file); I will use the message box so that the user will know what to do.  I can’t figure out how to make the macro close the secondary file if it cannot be opened as write access.

ActiveDocument.ReadOnly would return true if read only - though for your case you may need to reference the specific document, the readonly attribute could still be used - so

if ActiveDocument.ReadOnly=true then
'advise user of the problem and close whatever needs closing
'proceed as normal
end if

would be the sort of process to use I think - I hope this gives you what you need, but do ask any further questions to get clarification.
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Aidan Heritage


I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards. I'm based in the UK, so please allow for time differences when asking me questions from other parts of the world!


My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2017 All rights reserved.