如何在使用VBA打开Excel工作簿时绕过SharePoint“只读”警报。

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

我遇到的问题是,即使DisplayAlerts = FalseWorkbook.Open行运行时,我得到一个屏幕提示,说:“文件被locking以供(某些用户)编辑。是否要:查看阅读 – 仅复制或保存并编辑文件的副本。“ 还有一个checkbox,显示“当服务器文件可用时接收通知”。 DisplayAlerts = False似乎不能取消SharePoint提示。 任何想法为什么不会取消promt? 我想在代码中试图在编辑模式下打开的点,不能,然后去If Activeworkbook.Readonly Then行和退出的子。 现在,它停止并等待SharePoint提示中的select。

 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 

replace这一行:

 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