Fix Excel VBA QueryTable Refresh Crashes After Microsoft 365 Upgrade
Question details
Excel crashes or produces automation errors when running VBA macros to refresh MS Query QueryTables after updating to Microsoft 365.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Running a VBA macro to update and refresh legacy MS Query data connections in a workbook after a recent Microsoft Office update.
- Observed behavior
- Excel throws an automation error or completely crashes when returning data to the worksheet. Furthermore, the built-in workbook recovery process often corrupts or damages the file permanently.
Create a complete backup copy of your workbook before running or testing any VBA macros, as Excel's automatic recovery process may severely corrupt the file during this specific crash.
Declare the ListObject Variable Explicitly in VBA
Update your VBA code to store the target table in an explicit variable before triggering the refresh method to prevent memory and automation errors.
Inline references to ListObjects can sometimes cause memory handling issues in newer builds of Microsoft 365, leading to sudden crashes when data is returned from MS Query.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in Excel, and locate the module containing your refresh macro.
Find the line causing the crash, typically written as 'Sheet2.ListObjects(1).QueryTable.Refresh (False)'. Replace it with explicit variable declarations: Dim Listobj As ListObject Set Listobj = Sheet2.ListObjects(1) Listobj.QueryTable.Refresh False Listobj.Range.AutoFilter
Save your code and run the macro again. Storing the ListObject in a variable ensures Excel properly handles the object reference during the background query refresh.

Recreate Connections using Power Query
If the code adjustment does not resolve the crash, the legacy MS Query connection itself might be incompatible with your Microsoft 365 update.
Perform a Clean Installation of Microsoft Office
Corrupted database drivers or incomplete Office components from the upgrade process can cause MS Query to fail upon returning data.
Try WPS Office for a Stable Spreadsheet Experience
If Microsoft Excel continues to crash or corrupt your workbooks after updates, consider switching to WPS Office. It provides a lightweight, highly compatible alternative for handling complex spreadsheets and data analysis without the heavy overhead of Microsoft 365.
- 1. Download and Install: Get the free WPS Office installer from the official website and complete the quick installation process.
- 2. Open Your Workbooks: Launch WPS Spreadsheets and open your existing Excel (.xlsx or .xlsm) files directly.
- 3. Manage Your Data Safely: Enjoy a stable, crash-free environment while managing your data tables and spreadsheet connections.

Frequently Asked Questions
Why does Excel's recovery process damage my workbook after a VBA crash?
When Excel crashes mid-refresh while running an MS Query update, the file's internal XML structure can become corrupted or left incomplete. Excel's automatic recovery tries to strip out the broken elements, which often results in the permanent removal of your tables, connections, or VBA modules.
Will Power Query connections crash in VBA like MS Query?
Generally, Power Query (Get Data) is much more robust and stable in newer Microsoft 365 versions. Migrating legacy MS Query connections to Power Query and refreshing them via VBA typically resolves legacy automation errors entirely.
Can I downgrade Microsoft 365 to fix the QueryTable crash?
Yes, if your organization allows it, you can roll back Microsoft 365 to a previous build where the legacy MS Query refresh functioned correctly. You will need to use the Office Deployment Tool or command-line updates to revert to an older version.




