Suppose a workbook exists on a shared network drive, and is open by User A. If User B attempts to open this file by double clicking it, he gets something like the following prompt:
If User B instead attempts to open the workbook programmatically (perhaps with an add-in) using:
Workbooks.Open("N:\path_to_workbook\workbook.xlsx")
what happens, exactly? Does this above prompt appear? If so, can it be suppressed with Application.DisplayAlerts = False
? If Workbooks.Open
as shown above throws an exception in this case, do we need to try again using the ReadOnly argument, as:
Workbooks.Open("N:\path_to_workbook\workbook.xlsx", ReadOnly:=True)
I have read other posts (including this one ) that suggest that Workbooks.Open
in the first code snippet succeeds and the workbook is opened read-only, although this is not perfectly clear.
Unfortunately, I don't have a test environment configured to replicate this scenario myself, which would otherwise be the obvious answer.
I tested on our network drive environment, and found the following. If the file is opened by User A and User B attempts to open the file programmatically using Workbooks.Open
then the result will be a Read Only version of the file.
If you wish to control the opening of Read Only files than you may utilize the following code example to close it:
Sub Test()
Dim wb As Workbook
Set wb = Workbooks.Open("Path_To_Excel_File")
If wb.ReadOnly Then
MsgBox "File already in use"
wb.Close savechanges:=False
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.