Why am I suddently getting a VBA Automation Error in code that has been thoroughly tested?

Brass Contributor

The following code has never given an error until now:

Sheets("Template").Visible = True

 The error is

autmation error.jpg

I was able to eliminate the error by writing

Dim sh as Worksheet
set sh = Sheets("Template")
sh.Visible = True

This is the Office 365 version of Excel. Since Office apps are updated automatically, could an automatic update by Microsoft have caused this? There was an Excel update on Feb 13. 

1 Reply


Using a variable to reference the worksheet, as you've done in your workaround, is generally a good practice in VBA programming. It can help make your code more robust and easier to maintain, as well as potentially avoid issues like the one you encountered.


The runtime error -2147319767 (8028029) is a "Automation error" in VBA, indicating that there's an issue with automating or accessing a particular object or method. This error can occur due to various reasons, such as:

  1. Missing or corrupt system files: Sometimes, a Windows update or other software changes can lead to missing or corrupt system files, causing automation errors.
  2. References: Issues with references or missing libraries in your VBA project can also trigger automation errors. Check your VBA project's references to ensure they are all properly set and not marked as missing.
  3. Permissions: Insufficient permissions to access certain resources or files can lead to automation errors.
  4. Memory issues: Sometimes, running out of memory or other resource constraints can cause automation errors.
  5. Software conflicts: Conflicts with other software installed on your system can also lead to automation errors.

To troubleshoot and resolve this issue, you can try the following steps:

  1. Restart Excel: Sometimes, simply restarting Excel can resolve temporary issues.
  2. Check References: Review the references in your VBA project to ensure they are all correctly set and not marked as missing. Remove any unnecessary references.
  3. Check for Windows Updates: Ensure your system is up-to-date with the latest Windows updates.
  4. Run as Administrator: Try running Excel as an administrator to see if it resolves the permissions issue.
  5. Repair Office Installation: If the issue persists, you may need to repair your Office installation through the Control Panel.
  6. Disable Add-ins: Disable any third-party add-ins or plugins in Excel to see if they are causing conflicts.
  7. Debugging: Use VBA debugging tools such as breakpoints and stepping through the code to identify the specific line causing the error.
  8. Event Viewer: Check the Windows Event Viewer for any related error messages or events that could provide more information about the cause of the error.

If none of the above steps resolve the issue, you may need to provide more specific details about your VBA code and the circumstances under which the error occurs for further assistance. The text was created with the help of AI.


My answers are voluntary and without guarantee!


Hope this will help you.


Was the answer useful? Mark as best response and like it!

This will help all forum participants.