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 workbo
I had two "exact" blocks of VBA code, one executed, the other had the automation error. I ran the Debugger and it got stuck on the code block below:
Do While ie.readyState = READYSTATE_COMPLETE
Application.StatusBar = "Going to StackOverflow ..."
DoEvents
Loop
So, I pasted the code block that worked and the one that didn't into separate Microsoft word documents and then used the Review / Compare feature. It revealed the error:
Do While ie.readyState = READYSTATE_COMPLETE (equals sign - incorrect)
vs.
Do While ie.readyState <> READYSTATE_COMPLETE (double brackets - correct)
I highly suggest using Word to assist where visually it just isn't clear.
Yes!
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.
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