【问题标题】:How to bypass SharePoint "Read-Only" alert when opening an Excel Workbook with VBA.如何在使用 VBA 打开 Excel 工作簿时绕过 SharePoint“只读”警报。
【发布时间】:2015-12-09 17:28:52
【问题描述】:

当代码尝试运行时,我正在尝试检查下面的工作簿文件是否已在“编辑模式”下打开。我正在尝试计划何时会出错,因为文件中已经有其他人。我需要Workbook.OpenReadOnly = False 的形式打开,因为如果没有人在其中,我需要能够在更新后保存。

我遇到的问题是,即使在 DisplayAlerts = False 运行 Workbook.Open 行时,我也会在屏幕上看到提示“文件已锁定以供(某些用户)编辑。你想:查看只读副本或保存并编辑文件的副本。”还有一个复选框,上面写着“当服务器文件可用时接收通知”。 DisplayAlerts = False 似乎没有取消 SharePoint 提示。关于为什么不会取消提示的任何想法? 我想在代码中尝试以编辑模式打开但不能,然后转到If Activeworkbook.Readonly Then 行并退出子程序。现在它停止并等待 SharePoint 提示上的选择。

Sub SendFCSpec()

MsgBox ("Please wait while your comments are sent to the database.")
ActiveSheet.Unprotect Password:="BAS1"
'Turn Screen Updating and Alerts off
Application.ScreenUpdating = False
Application.DisplayAlerts = False

'Disable Macros on AutoOpen of the Excel Workbook
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Workbooks.Open Filename:="http://Sharepoint.com/QA/FC%20QA%20Workshop/Databases/Dec/FC%20Spec%20Database.xlsm", _
UpdateLinks:=3, ReadOnly:=False
If ActiveWorkbook.ReadOnly Then
    ActiveWorkbook.Close
    MsgBox "Another user has the database open. Unable to submit comments at this time."
    Application.AutomationSecurity = msoAutomationSecurityLow
    Exit Sub
End If
Application.AutomationSecurity = msoAutomationSecurityLow

ActiveWorkbook.Save
ActiveWorkbook.Close

ActiveSheet.Select
ActiveSheet.Protect Password:="BAS1", DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, AllowSorting:=True, AllowFiltering:=True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox ("Comments have been saved to the Database. Thanks")
End Sub  

【问题讨论】:

    标签: excel vba sharepoint


    【解决方案1】:

    替换这一行:

    Workbooks.Open _
        fileName:="http://Sharepoint.com/QA/FC%20QA%20Workshop/Databases/Dec/FC%20Spec%20Database.xlsm", _
        UpdateLinks:=3, ReadOnly:=False
    

    用这一行:

    Workbooks.Open _
        fileName:="http://Sharepoint.com/QA/FC%20QA%20Workshop/Databases/Dec/FC%20Spec%20Database.xlsm", _
        UpdateLinks:=3, ReadOnly:=False, Notify:=False
    

    【讨论】:

    • 哇。我通读了 Workbook.Open 帮助指南,完全没有看到 Notify 解释的其余部分。谢谢!
    【解决方案2】:

    我创建了一个 WB,将它作为 Book1 以只读方式保存到我的桌面。我尝试了上述方法,但仍然弹出。我将 'ReadOnly:=' 从 False 更改为 True 并且它起作用了。自己试试吧。

    Sub Test()
    Dim File1 As String
    File1 = Environ("USERPROFILE") + "\Desktop\Book1.xlsx"
    Workbooks.Open Filename:=File1, ReadOnly:=True, Notify:=False
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多