How to open Locked for Editing file as Read Only?

mitchmitch24 picture mitchmitch24 · Dec 14, 2017 · Viewed 8.3k times · Source

I have a macro that opens multiple files. If it comes to a file "Locked for Editing" it will give me an error saying

FileName is currently in use. Try again later.

How can I make it open said file as read only? I tried:

Workbooks.Open FileName:=Selected_EOS_Report_File, ReadOnly:=True

and

Workbooks.Open FileName:=Selected_EOS_Report_File, ReadOnly:=True, IgnoreReadOnlyRecommended:=True

Update: The first method does work. My code runs on multiple files that pass through the "Selected_EOS_Report_File" variable. At some point a file passed through that was an Excel temp file (begins the filename with "~$"). I created an if/then statement to skip over any such files.

Answer

dadler picture dadler · Dec 14, 2017

As far as I know, you need Notify:= True

MSDN link

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.