我有一个脚本,它运行在几千个工作簿的列表中,并从每个工作簿中获取数据。
当脚本尝试打开某些工作簿时,我收到以下错误:
Compile Error: Can't find project or library
我认为我可以避免此消息,我理解这是由于引用问题,通过打开没有宏的工作簿或以这种方式提醒:
dim bk as workbook
for each path in listOfWorkbookPaths
Application.DisplayAlerts = False
Application.EnableEvents=false
set bk=workbooks.open(path)
Application.EnableEvents=true
Application.DisplayAlerts = True
collectData(bk)
next
但这不起作用;我仍然得到编译错误。有没有办法确保没有弹出这个错误?
答案 0 :(得分:1)
您需要更改AutomationSecurity
设置:
Sub ImportFromExternalWorkbooks() Dim bk as Workbook Dim secAutomation As MsoAutomationSecurity secAutomation = Application.AutomationSecurity Application.AutomationSecurity = msoAutomationSecurityForceDisable For Each path in listOfWorkbookPaths Set bk=Workbooks.Open(path) collectData bk Next Application.AutomationSecurity = secAutomation End Sub