萬盛學電腦網

 萬盛學電腦網 >> Excel教程 >> excel綜合 >> 使用CreateObject創建Excel實例代碼

使用CreateObject創建Excel實例代碼

  一、使用CreateObject創建Excel

  Sub LateBinding()

  'Declare a generic object variable

  Dim objExcel As Object

  'Point the object variable at an Excel application object

  Set objExcel = CreateObject("Excel.Application")

  'Set properties and execute methods of the object

  With objExcel

  .Visible = True

  .Workbooks.Add

  .Range("A1") = "Hello World"

  End With

  End Sub

  二、使用CreateObject創建指定版本的Excel實例

  Sub mate()

  Dim objExcel As Object

  Set objExcel = CreateObject("Excel.Application.8")

  End Sub

  當Create對象實例之後,就可以使用該對象的所有屬性和方法了,如SaveAs方法、Open方法、Application屬性等。

copyright © 萬盛學電腦網 all rights reserved