I have a number of Excel files that refresh themselves via macro, and a master file to control opening the other. The master file has an Auto_Open macro that opens each doc, runs the macro in the doc, then closes it. 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.
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. 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.
I have tried to find the library as suggested by Microsoft (https://learn.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/can-t-find-project-or-library) but to no avail. 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. The crash returns this error text:
Problem signature:
Problem Event Name: APPCRASH
Application Name: EXCEL.EXE
Application Version: 16.0.11231.20130
Application Timestamp: 5c518be9
Fault Module Name: VBE7.DLL
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 5c064824
Exception Code: c0000005
Exception Offset: 00000000000b555a
OS Version: 6.3.9600.2.0.0.272.7
Locale 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)
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