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
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.
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