如何通过使用macros来重新打开工作簿并禁止私人子工作簿_打开

我想重新打开只读工作簿作为读取和写入来改变macros的值。

我想通过重新打开工作簿来抑制私人子工作簿_open:

Private Sub Workbook_Open() Application.DisplayAlerts = False On Error Resume Next ActiveWorkbook.ChangeFileAccess Mode:=xlReadOnly 

任何人都可以帮我解决这个问题吗?

我知道我必须使用临时工作簿来运行重新打开的macros。 但是我找不到合适的vba代码。

假设我们有一个名为yesterday.xlsm的工作簿,我们要打开这个工作簿,但是我们不是昨天的Open Eventmacros来触发的。 在另一个工作簿中运行此操作:

 Sub PardonMyParanoia() Application.EnableEvents = False Workbooks.Open Filename:="C:\TestFolder\yesterday.xlsm" End Sub 

这不是testing的代码,但应该打开禁用macros的工作簿。

 Public Function OpenWorkbookWithMacrosDisabled(ByRef filePathAndName As String, Optional ByRef openReadOnly As Boolean = False) As Boolean ' Stores the current security settings ' sets the security to High, then opens the workbook ' Sets the security settings back to their original settings ' Simon Leten 27-Jun-2014 Dim secAutomation As MsoAutomationSecurity Dim nameOfFile As String Dim result As Boolean ' *** Leave errors to get handled by the calling proc *** ' On Error GoTo ErrorHandler ' *** Leave errors to get handled by the calling proc *** Const PROC_NAME As String = "OpenWorkbookWithMacrosDisabled" result = False secAutomation = Application.AutomationSecurity nameOfFile = Dir$(filePathAndName) If nameOfFile = "" Then Err.Raise vbObjectError + 0, PROC_NAME, "Cannot find the file '" & filePathAndName & "'." Else If WorkbookIsOpen(nameOfFile) Then Err.Raise vbObjectError + 0, PROC_NAME, "A file with the name '" & nameOfFile & "' is already open." Else Application.AutomationSecurity = msoAutomationSecurityForceDisable Application.Workbooks.Open Filename:=filePathAndName, ReadOnly:=openReadOnly, AddToMru:=False result = True End If End If ExitProc: Application.AutomationSecurity = secAutomation OpenWorkbookWithMacrosDisabled = result Exit Function End Function