Pages

Showing posts with label ActiveXObjects. Show all posts
Showing posts with label ActiveXObjects. Show all posts

Thursday, July 14, 2011

"Automation server can't create object" - Occuring with "ActiveXObject('Word.Application')"

This specific error occurs when your browser does not support ActiveXObjects or it does support ActiveX but the security features configured does not allow it to proceed.

Hence to fix this issue ActiveX controls must be allowed in the browser


Go to Tools -> Internet Options -> Security -> Custom Level and make the following changes under the ActiveX Controls and plug-ins section




1. Enable - Allow prompting for ActiveX controls   (optional/probable)

2. Enable - Download signed ActiveX controls

3. Enable - Initialize and script ActiveX controls not marked as safe for scripting


Hope this helps :)

Try catch doesnot catch ActiveXObject errors

I had been thinking about making a post on this for a very long time. Unfortunately for some reason , I kept forgetting about it from time to time. And at last I have even forgot that I faced such an issue in the past until recently.

As per my understanding errors that occur due to automation object creation failures when attempting to create ActiveX Objects can't be handled by try catch block. Instead, one must check it right up front to give the desired error message to the user.

the following is a simple illustration of what i am speaking about,

try{
...
var obj=new ActiveXObject("Blah blah blah");   // suppose error occurs in this statement
...
} catch (activeXError) {
  // the error that occured due to active x object creation failure does not get captured here and hence any
  //code that you exectute here does not get executed. Rather you can find an abrupt error message in the
  //console
}

So in order to handle it, you must check it upfront,

if (window.ActiveXObject) {
  ... blah blah blah....
} else {
  // report error
}

Hope that helps :)