源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

VBS教程:函数-CreateObject 函数

  • 时间:2021-05-18 14:38 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:VBS教程:函数-CreateObject 函数

CreateObject 函数

创建并返回对 Automation 对象的引用。 [code][b]CreateObject([/b]servername.typename [[b],[/b] location][b])[/b][/code] [h3]参数[/h3]servername 必选项。提供对象的应用程序名称。 typename 必选项。要创建的对象类型或类。 location 可选项。对象所在的网络服务器将被创建。 [h3]说明[/h3]Automation 服务器至少提供一种对象类型。例如,字处理应用程序可以提供应用程序对象、文档对象和工具条对象。 要创建 Automation 对象,将 [b]CreateObject[/b] 函数返回的对象赋值给某对象变量:
[code]Dim ExcelSheetSet ExcelSheet = [b]CreateObject([/b]"Excel[b].[/b]Sheet"[b])[/b][/code]
上述代码启动创建对象(在此实例中,是 Microsoft Excel 电子表格)的应用程序。对象创建后,就可以在代码中使用定义的对象变量引用此对象。在下面的示例中,可使用对象变量、ExcelSheet 和其他 Excel 对象,包括 Application 对象和 Cells 集合访问新对象的属性和方法。例如:
[code]' Make Excel visible through the Application object.ExcelSheet.Application.Visible = True' Place some text in the first cell of the sheet.ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1"' Save the sheet.ExcelSheet.SaveAs "C:\DOCS\TEST.XLS"' Close Excel with the Quit method on the Application object.ExcelSheet.Application.Quit' Release the object variable.Set ExcelSheet = Nothing[/code]
在远程服务器上创建一个对象,当 Internet 安全关闭时只能完成。通过传递计算机名到 [b]CreateObject[/b] 服务器名的参数,能在远程网络上创建对象。该名称如同共享部份的机器名。例如网络共享名命名为: "\\myserver\public", [i]servername[/i] 是 "myserver"。另外,只能指定 [i]servername[/i] 使用 DNS 格式或 IP 地址。 以下代码返回运行在命名为"myserver"的远程网络计算机上 Excel 实例的版本号 :
[code]Function GetVersion  Dim XLApp  Set XLApp = CreateObject("Excel.Application", "MyServer")  GetVersion = XLApp.VersionEnd Function[/code]
错误发生在指定的远程服务器不存在或无法找到。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部