ActiveXObject 对象

此对象提供自动化对象的接口。

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

参数

  • ProgID
    必选。 形式为“serverName.typeName”的字符串,其中 serverName 是提供对象的应用程序的名称,typeName 是要创建的对象的类型或类。

  • location
    可选。 要在其中创建对象的网络访问器的名称。

备注

通常,自动化服务器会提供至少一种对象。 例如,字处理应用程序可能会提供应用程序对象、文档对象和工具栏对象。

以下代码通过调用 ActiveXObject 对象构造函数来启动应用程序(在这种情况下为 Microsoft Excel 工作表)。 ActiveXObject 允许您在代码中引用应用程序。 使用下面的示例,您可以使用对象变量 ExcelSheet 和其他 Excel 对象(包括应用程序对象和 ActiveSheet.Cells 集合)来访问新对象的属性和方法。

// 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();

若要在远程服务器上创建对象,只能在关闭 Internet 安全机制时完成。 您可以通过将计算机的名称传递到 ActiveXObjectservername 参数在远程网络计算机上创建对象。 该名称与共享名的计算机名部分相同。 对于名为“\\MyServer\public”的网络共享,servername 为“MyServer”。 此外,您可以使用 DNS 格式或 IP 地址来指定 servername

以下代码返回在名为“MyServer”的远程网络计算机上运行的 Excel 实例的版本号:

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

如果指定的远程服务器不存在或者找不到,则会出错。

属性和方法

ActiveXObject 对象不具有任何内部属性或方法;它允许您访问自动化对象的属性和方法。

要求

版本 1

请参见

参考

new 运算符

GetObject 函数 (JScript 10.0)