2

I'm building a small web application that needs to access Powerpoint through ActiveX and Javascript (and IE9...) to automatically build a report. I'm am using ActiveX because I can't generate the Powerpoint file on the server side (although I would have prefered this very much).

My code right now is very bare boned as I'm just beginning:

// Creating the ActiveX Powerpoint control
var ppt;
try{
    ppt = new ActiveXObject("Powerpoint.Application");
}catch(e){
    if (e instanceof ReferenceError)
        alert("Your browser might not be compatible with this function. Please use Internet Explorer.");
    else
        alert("An error happened: " + e);
}
console.log("ActiveX Object created");

// Openning Powerpoint, make it visible
ppt.Visible = 1;

// Creating a new Presentation, and adding a blank (1 slide, 1 = ppLayoutBlank) Slide
ppt.Presentations.Add();
ppt.ActivePresentation.Slides.Add(1, 1);

On my computer, it happens that the ActiveX control doesn't launch Powerpoint even if I allow it to execute through the "An ActiveX control on this page might be dangerous; Do you allow it to execute?" (traduced straight from French).

But, if I launch the Developper Console, it magically runs. And, on another computer with IE 11, it works fine after I allowed the ActiveX control to execute.

I think my IE Security settings are right, thus I can't think of anything else that an IE glitch I'm not aware of. I'm working with IE 9.0.8112.16421 64-bit.

How could I get this code to run nicely? Thank you in advance!

Remy San
  • 525
  • 1
  • 4
  • 24
  • 3
    `console.log` in IE works only if Developer console is open... if Developer Console is closed its stops the script because console is `undefined`. Try to change `console.log("ActiveX Object created");` in `try{console.log("ActiveX Object created")}catch(err){}`. – Frogmouth Jan 14 '15 at 14:44
  • 2
    Or just change it to an `alert("ActiveX Object created");` – ToastyMallows Jan 14 '15 at 14:48
  • Wow... Well played IE, well played! I actually briefly through of that but would never have thought this was the issue! It works perfectly with the `try catch`, I'll stick with that then! @Frogmouth If you might post this as answer, so I can accept it... Thank you two for the lightning-fast answer! – Remy San Jan 14 '15 at 14:51
  • 1
    @ToastyMallows - Is an other way, but (I think) it's a `log` for the developer not an `alert` for user . – Frogmouth Jan 14 '15 at 14:56
  • 1
    @Frogmouth Well basically it's just a brief "starting developement" log to check if everything is alright. I might drop it soon as I will progress on the developement. I'm just used to use `console.log` instead of `alert` when it's not directed to the user. – Remy San Jan 14 '15 at 15:01
  • @Frogmouth yes, but when you're just testing an `alert` is nice to see as a good visual indicator that some breakpoint is hit. – ToastyMallows Jan 14 '15 at 17:09
  • Does this answer your question? [Why does JavaScript only work after opening developer tools in IE once?](https://stackoverflow.com/questions/7742781/why-does-javascript-only-work-after-opening-developer-tools-in-ie-once) – 273K Sep 19 '22 at 23:55

1 Answers1

4

Remind: console.log in IE works only if Developer console is open. If the Developer Console is closes it stops the script because console is undefined.

In your code, try to change:

console.log("ActiveX Object created");

with

try{console.log("ActiveX Object created")}catch(err){} or comment the line with: //.

Frogmouth
  • 1,808
  • 1
  • 14
  • 22