Search code examples
javascriptgoogle-apps-scriptactivex

Google Apps Script: Referencing the ActiveXObject


I wish to create an Excel object from within App Script. The following resource:

http://www.webdeveloper.com/forum/showthread.php?249479-Javascript-excel-object

shows how to do so using Javascript - I was therefore hopeful that I could use this code within Google Apps Script:

function xlTest() {
    var xls = new ActiveXObject ( "Excel.Application" );
    var newBook = xls.Workbooks.Add;
    newBook.Worksheets.Add;
    newBook.Worksheets(1).Activate;
}

When I try to run this function I get the error message:

ReferenceError: "ActiveXObject" is not defined

Hopefully I simply need to add a reference to ActiveXObject, if so could somebody please advise how I add a reference to ActiveXObject from Google Apps Script? Many thanks!


Solution

  • The question has nothing to do with Google Apps Script (or even JavaScript) and should not be tagged as such. You can't simply throw this code into Google Script Editor and expect things to work.

    GAS is a JavaScript-based runtime that lives on Google servers, not in your browser. It doesn't have access to BOM (Browser Object Model) Furthermore, ActiveX is not supported in most browsers, including Microsoft Edge. Of course, VBA methods like Sheets.Add won't work for obvious reasons.

    If you log the global object in Script Editor, you'll see all of its properties available to you as a developer. enter image description here

    In your browser, the properties of global object will be different:

    enter image description here

    Please take the time to go through GAS documentation and understand features & limitations https://developers.google.com/apps-script/