EnableEvents不起作用

我是VBA新手,在开发下面的代码时遇到问题。 代码将希望通过大约500多个文件运行,并从各种单元中提取一些数据。 一旦我用enableevents解决这个问题。 目前,每个xls文件popup“启用或禁用macros”框。 任何帮助将是伟大的。

Sub ProcessAll(Optional sPath As Variant) Dim WB As Workbook, sFile As String Application.ScreenUpdating = False Application.DisplayAlerts = False Application.EnableEvents = False If IsMissing(sPath) Then sPath = "U:\Desktop\Temp\PEP Temp\" sFile = Dir(sPath & "*.xls") End If 'Loop through all .xls-Files in that path Do While sFile <> "" Set WB = Workbooks.Open(sPath & sFile, , ReadOnly = True, , , , , , , , Notify = False) Debug.Print WB.Name WB.Close False sFile = Dir Loop Application.ScreenUpdating = True Application.DisplayAlerts = True Application.EnableEvents = True End Sub 

在做了一些研究之后,我发现你可以用下面一行代码强制excelselect禁用macros

 Application.AutomationSecurity = msoAutomationSecurityForceDisable 

从Excel菜单:文件>保密中心>参数>macros参数>select你需要的一个。

我试图把它变成一个VBAmacros使用develeopper>loggingmacros,但没有成功…

所以我认为你必须手动做。