Share via


ActiveXObject 物件

更新:2007 年 11 月

提供 Automation 物件介面的物件。

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

引數

  • ProgID
    必要項。格式為 serverName.typeName 的字串,其中 serverName 是提供物件的應用程式名稱,而 typeName 是要建立之物件的型別或類別 (Class) 名稱。

  • location
    選擇項。網路伺服器名稱,即要在其中建立物件的網路伺服器。

備註

通常,Automation 伺服程式至少會提供一種物件。例如,文字處理應用程式可能會提供一個應用程式物件、一個文件物件和一個工具列物件。

下列程式碼藉著呼叫 ActiveXObject 物件建構函式 (Constructor) 來啟動應用程式 (在本例中是 Microsoft Excel 工作表)。ActiveXObject 讓您在程式碼裡參考應用程式。使用下列範例,您可以使用物件變數 ExcelSheet 和其他的 Excel 物件 (包括 Application 物件和 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();

只有在關閉網際網路安全性時,才能完成在遠端伺服器上建立物件的動作。您可以藉著將遠端網路電腦的名稱傳遞至 ActiveXObjectservername 引數,來建立該電腦上的物件。此名稱與共用名稱的電腦名稱部分相同。對於網路共用名稱 \\MyServer\public 來說,servername 為 MyServer。此外,您也可以使用 DNS 格式或 IP 位址來指定 servername

下列程式碼傳回在遠端網路電腦上執行之 Excel 的執行個體 (Instance) 的版本編號 (此遠端網路電腦的名稱為 MyServer):

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

如果指定的遠端伺服器不存在或找不到,則會發生錯誤。

屬性和方法

ActiveXObject 物件沒有內建 (Intrinsic) 屬性或方法;它允許您存取 Automation 物件的屬性和方法。

需求

1 版

請參閱

參考

new 運算子

GetObject 函式 (JScript 8.0)