Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation Error

Status
Not open for further replies.

Tonyqu

Technical User
Dec 20, 2022
1
FR
Hi,
I have some vba code and sometimes when i try to run the code i am getting an "Automation Error" message.
May i know what is this please? and has anyone got this issue before please?
Thanks a lot
 
A general description from MS here.

An example (excel) when variable was not cleared (set to Nothing), still refers to non-existing object and the code tries to access it:
[pre]Sub AutomationErrTest()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets.Add
ws.Delete
MsgBox ws.Name
End Sub[/pre]

VBA has dedicated forum707

combo
 
We probably need to see the code to answer this.

In the absence of being able to show us all the code, can you at least show the line of code that is causing the problem? The error message dialog should have a 'Debug' button, clicking that should take you to the troublesome line of code.

>May i know what is this please?
Given you are listed as a 'TechnicalUser' I'm not sure what your level of VBA knowledge is, but I hope the following makes some sense: a general answer is that VBA can use objects. One use of these is to access and control other applications - to 'automate' them. You can also use local objects within your VBA host (e.g Excel ranges). This is also considered 'automation'.

However, sometimes there is a problem with an object (e.g it may not have a valid reference at the time you try to use it). This manifests as an 'automation error'

An (contrived) example in Excel might be:

Code:
[COLOR=blue]Sub CrashAutomation()
  Dim wb As Workbook
  Set wb = Workbooks.Add [COLOR=green]' OK, wb now references a new workbook[/color]
  wb.Close [COLOR=green]' Close the workbook. Reference is no longer valid[/color]
  wb.Activate [COLOR=green]' Automation error as we are trying to use a method on an invalid object reference[/color]
End Sub[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top