I have a worksheet named "Dates" (object name is A_Dates) that needs to be calculated when it is activated (It may be worth noting that this is in my Personal macro workbook). I regularly have workbooks open that have too many calculations in the for me to have auto-calculation on. So I have auto-calc set to manual, and the following code in the worksheet:
Private Sub Worksheet_Activate()
A_Dates.Calculate
End Sub
This has worked fine for the last 3 months, day-in and day-out. Yesterday, it stopped working. It now throws this error on the declaration line:
Microsoft Visual Basic
Automation error
Unspecified error
[OK] [Help]
I have tried changing how I reference the sheet, using:
Sheets("Dates").Calculate
and
ActiveSheet.Calculate
to no avail. I've also included error handling:
On Error Resume Next
which doesn't prevent it. I've even gone so far as:
Private Sub Worksheet_Activate()
On Error GoTo headache
Sheets("Dates").Calculate
Exit Sub
headache:
Exit Sub
End Sub
and it still shows up. I am totally at a loss. Help?
I have the following references, and use all of them in various macros in this workbook:
Visual Basic for Applications
An automation error could occur when you are referring to a workbook or worksheet via a variable, but the variable is no longer active. Make sure any object variables that you are referring to in your code are still valid when you call the property and methods that you are controlling them with.
If you get the message "automation error" when you open Excel after installing or when you click on the icon to open the add-in, the problem is caused by a problem with the installation of Microsoft Office. There is not a problem with the add-ins. Re-installing our add-ins does not solve.
This error has the following causes and solutions: You tried to run code from the Macro dialog box. However, Visual Basic was already running code, although the code was suspended in break mode. You may have entered break mode without knowing it, for example, if a syntax error or run-time error occurred.
We ran into the same problem, but with a twist - we have several people all using the same macros successfully, but one is having the "Automation Error" "Unspecified Error" problem. The other answer helped me identify that the problem might be due to the "Microsoft ProgressBar Control". (Thank you very much)
But instead of removing the form, I unregistered and registered the MSCOMCTL.OCX on the user's PC that was having problems and he's back in business again. I wish I knew what caused the registration of the control to go south - this is not the first time I've had to track down problems with this control.
To unregister and register the control:
Use an “Elevated command prompt” (command prompt run as an administrator), issue the following commands:
Regsvr32 /u c:\windows\SysWOW64\MSCOMCTL.OCX
Regsvr32 c:\windows\SysWOW64\MSCOMCTL.OCX
NOTE: the /u unregisters the ocx
Whenever I get strange errors like this, the first thing I do is clean the code with http://www.appspro.com/Utilities/CodeCleaner.htm. It's a free add-in, but you can do it manually too. Just copy your code out of the module and into a text file (or right click and Export). Then delete the code in the module, compile and save, and put the code back in.
When Excel compiles "on the fly" it's creating p-code which then gets compiled to machine code. Sometimes, particularly with heavy editing, the p-code gets corrupted. Copying the code out, deleting it, and copying back in forces Excel to regenerate the p-code.
I've solved some really strange behavior with this method. Hopefully it works for you too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With