简体   繁体   English

找不到项目或库使一切崩溃

[英]Can't find project or library crashes everything

I have a number of Excel files that refresh themselves via macro, and a master file to control opening the other.我有许多 Excel 文件可以通过宏刷新自己,还有一个主文件来控制打开另一个文件。 The master file has an Auto_Open macro that opens each doc, runs the macro in the doc, then closes it.主文件有一个 Auto_Open 宏,它打开每个文档,在文档中运行宏,然后关闭它。 Each doc's macro essentially refreshes all the queries inside and saves the doc in two different places.每个文档的宏本质上都会刷新里面的所有查询,并将文档保存在两个不同的地方。 To top it all of, I am using Window's Task Scheduler to open the master doc every two hours, kicking off the whole process.最重要的是,我使用 Window 的任务计划程序每两个小时打开一次主文档,启动整个过程。

This generally works pretty well.这通常效果很好。 However, I will occasionally get an error for one the docs that says "Cannot find project or library."但是,我偶尔会收到一个错误,提示“找不到项目或库”。 This occurs seemingly at random and with a different doc each time (though never the master doc).这似乎是随机发生的,并且每次都有不同的文档(尽管从来不是主文档)。 Once this error appears, Excel will crash completely every time I try to open the VBA window.一旦出现此错误,每次我尝试打开 VBA 窗口时,Excel 都会完全崩溃。 The macro in said doc will no longer run via the master file's Auto_Open macro, and I have to recreate said doc from scratch.所述文档中的宏将不再通过主文件的 Auto_Open 宏运行,我必须从头开始重新创建所述文档。

I have tried to find the library as suggested by Microsoft ( https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/can-t-find-project-or-library ) but to no avail.我试图找到微软建议的库( https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/can-t-find-project-or-图书馆)但无济于事。 Opening the VBA window in the affected file causes an immediate crash, and following the steps in the article above for an unaffected file reveals nothing wrong.在受影响的文件中打开 VBA 窗口会导致立即崩溃,并且按照上述文章中针对未受影响的文件中的步骤没有发现任何问题。 The crash returns this error text:崩溃返回此错误文本:

Problem signature:问题签名:

Problem Event Name: APPCRASH问题事件名称:APPCRASH

Application Name: EXCEL.EXE应用程序名称:EXCEL.EXE

Application Version: 16.0.11231.20130应用版本:16.0.11231.20130

Application Timestamp: 5c518be9应用时间戳:5c518be9

Fault Module Name: VBE7.DLL故障模块名称:VBE7.DLL

Fault Module Version: 0.0.0.0故障模块版本:0.0.0.0

Fault Module Timestamp: 5c064824故障模块时间戳:5c064824

Exception Code: c0000005异常代码:c0000005

Exception Offset: 00000000000b555a异常偏移:00000000000b555a

OS Version: 6.3.9600.2.0.0.272.7操作系统版本:6.3.9600.2.0.0.272.7

Locale ID: 1033区域设置 ID:1033


Code in Master File:主文件中的代码:

Sub Auto_Open()

Application.Wait (Now + TimeValue("0:00:10"))

Application.Calculation = xlCalculationManual

Workbooks.Open ("C:\Users\aowens\Desktop\Queries\ATSReports\ATSReports.xlsm")
Application.Run "'C:\Users\aowens\Desktop\Queries\ATSReports\ATSReports.xlsm'!Macro"
Workbooks("ATSReports.xlsm").Close False

Workbooks.Open ("C:\Users\aowens\Desktop\Queries\MiscLookups\MiscLookups.xlsm")
Application.Run "'C:\Users\aowens\Desktop\Queries\MiscLookups\MiscLookups.xlsm'!Macro"
Workbooks("MiscLookups.xlsm").Close False

(this pattern repeats for 5 other files) (此模式对其他 5 个文件重复)

Sample macro within one the files:一个文件中的示例宏:

Sub Macro()

Dim errorcount
Dim broken
Dim this As Date

this = now()
errorcount = 0

On Error Resume Next

ThisWorkbook.Connections("Query - MasterROCL").Refresh
If Err <> 0 Then
errorcount = errorcount + 1
broken = broken & " ROCL"
End If
Err = 0

ThisWorkbook.Connections("Query - MasterRMEL").Refresh
If Err <> 0 Then
errorcount = errorcount + 1
broken = broken & " RMEL"
End If
Err = 0

ThisWorkbook.Connections("Query - MasterRHIL").Refresh
If Err <> 0 Then
errorcount = errorcount + 1
broken = broken & " RHIL"
End If
Err = 0

ThisWorkbook.Connections("Query - MasterREXH").Refresh
If Err <> 0 Then
errorcount = errorcount + 1
broken = broken & " REXH"
End If
Err = 0

Calculate

ThisWorkbook.Save
Application.DisplayAlerts = False
ThisWorkbook.SaveAs ("R:\Operations\Dashboards\Queries\ATSReports.xlsm")

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.to = "aowens@explorenetwork.org"
.Subject = errorcount & " Errors for " & Format(now(), "MM/DD HH:MM") & " ATS Refresh"
.htmlBody = " ~ " & Round(1440 * (TimeValue(now()) - TimeValue(this)), 0) & " mins. Broken:" & broken
.Send
End With

End Sub

I often run into the same error as you under similar circumstances.在类似的情况下,我经常遇到和你一样的错误。 I can't tell you what causes the error or how to stop it but i can help with this我无法告诉您导致错误的原因或如何阻止它,但我可以提供帮助

"and I have to recreate said doc from scratch." “我必须从头开始重新创建所述文档。”

To recover the file you need to open the file in Excel's safe mode (hold ctrl and open Excel to activate Safe Mode) then open VBE > Debug > Compile Project.要恢复文件,您需要在 Excel 的安全模式下打开文件(按住 ctrl 并打开 Excel 以激活安全模式),然后打开 VBE > 调试 > 编译项目。 Then save and close, next time you open the file it should be fine.然后保存并关闭,下次打开文件时应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM