I have some VBA code in an Excel workbook that opens another workbook just to copy and paste some cells back into the first workbook. Therefore, I only need to open it read-only.
The current line of code:
Workbooks.Open Filename:=qBDARsvFile, ReadOnly:=True, UpdateLinks:=False
If someone else is currently in the file, I get an error. I thought the ReadOnly:=True part of the code would allow the workbook to be opened still. What am I missing?
1 Answer
I think you want Notify:= True, see the workbooks.open language reference.
Notify
If the file cannot be opened in read/write mode, this argument is True to add the file to the file notification list. Microsoft Excel will open the file as read-only, poll the file notification list, and then notify the user when the file becomes available. If this argument is False or omitted, no notification is requested, and any attempts to open an unavailable file will fail.
(Emphasis mine)
This should allow you to open the file, read your cells and then close it again, even if it is already in-use.