Udostępnij za pośrednictwem


ActiveXObject Object

An object that provides an interface to an Automation object.

function ActiveXObject(ProgID : String [, location : String])

Arguments

  • ProgID
    Required. A string of the form "serverName.typeName", where serverName is the name of the application providing the object, and typeName is the name of the type or class of the object to create.

  • location
    Optional. The name of the network server where the object is to be created.

Remarks

Typically, an automation server provides at least one type of object. For example, a word-processing application may provide an application object, a document object, and a toolbar object.

The following code starts an application (in this case, a Microsoft Excel worksheet) by calling the ActiveXObject object constructor. The ActiveXObject allows you to refer to the application in your code. Using the following example, you can access properties and methods of the new object using the object variable ExcelSheet and other Excel objects, including the Application object and the ActiveSheet.Cells collection.

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\TEST.XLS");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();

Creating an object on a remote server can only be accomplished when Internet security is turned off. You can create an object on a remote networked computer by passing the name of the computer to the servername argument of ActiveXObject. That name is the same as the machine name portion of a sharename. For a network share named "\\MyServer\public", the servername is "MyServer". In addition, you can specify servername using DNS format or an IP address.

The following code returns the version number of an instance of Excel running on a remote network computer named "MyServer":

function GetAppVersion() {
   var Excel = new ActiveXObject("Excel.Application", "MyServer");
   return(Excel.Version);
}

An error occurs if the specified remote server does not exist or cannot be found.

Properties and Methods

An ActiveXObject object has no intrinsic properties or methods; it allows you to access the properties and methods of the Automation object.

Requirements

Version 1

See Also

Reference

new Operator

GetObject Function (JScript 10.0)