当代码尝试运行时,我正在尝试检查下面的工作簿文件是否已在“编辑模式”下打开。我正在尝试计划何时会出错,因为其他人已经在文件中。我需要将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
答案 0 :(得分: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
答案 1 :(得分:0)
我创建了一个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