简体   繁体   English

在其他用户打开的共享驱动器上打开工作簿(或其他 Office 文档)

[英]Opening a workbook (or other Office doc) on a shared drive that another user has open

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:假设一个工作簿存在于共享网络驱动器上,并且由用户 A 打开。如果用户 B 尝试通过双击打开该文件,他会得到类似以下提示:

在此处输入图片说明

If User B instead attempts to open the workbook programmatically (perhaps with an add-in) using:如果用户 B 尝试使用以下方法以编程方式(可能使用加载项)打开工作簿:

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 ?如果是这样,是否可以使用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在这种情况下如上所示抛出异常,我们是否需要使用 ReadOnly 参数再次尝试,如:

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.我已经阅读了其他帖子(包括这个),这些帖子表明第一个代码片段中的Workbooks.Open成功并且工作簿以只读方式打开,尽管这并不完全清楚。

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.如果文件由用户 A 打开,而用户 B 尝试使用Workbooks.Open以编程方式打开文件,则结果将是文件的只读版本。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取在网络驱动器上打开文件的用户的用户名 - Microsoft Office Style - Get username of user who has file open on network drive - Microsoft Office Style 打开另一个用户和域下的共享文件? - Open a shared file under another user and domain? 如果其他实例拥有该用户,则阻止用户打开表单 - Block user from opening a form if other instance has this user FileStream / StreamWriter(如果另一个用户打开了文件) - FileStream/StreamWriter if another user has the file open 清除Office剪贴板,以便复制的数据不与其他Office程序共享 - Clearing office clipboard so that copied data is not shared with other office programs Microsoft.Office.Interop.Word.Application.Documents.Open(“C:\\ doc.doc”)未打开 - Microsoft.Office.Interop.Word.Application.Documents.Open(“C:\\doc.doc”) not open 从硬盘驱动器打开Office文档时以模式方式打开exe(Windows应用程序) - Opening an exe(windows app) as modal while opening an office document from hard drive C# 打开 excel 工作簿后,如何防止用户在同一个 excel 实例中打开另一个 excel 文件(通过 windows)? - C# After opening an excel workbook, how can I prevent a user from opening another excel file(via windows) in the same excel instance? 当另一个用户打开事务时在数据库上添加表 - Add table on DB when another user has a transaction open 从Sharepoint打开Visio文档时出错(Sharepoint Office互操作问题) - Error while opening Visio doc from Sharepoint (Sharepoint Office interop issue)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM