【发布时间】:2015-12-09 17:28:52
【问题描述】:
当代码尝试运行时,我正在尝试检查下面的工作簿文件是否已在“编辑模式”下打开。我正在尝试计划何时会出错,因为文件中已经有其他人。我需要Workbook.Open 以ReadOnly = 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