一、使用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
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/diannaorumen/)With objExcel
.Visible = True
.Workbooks.Add
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/diannaorumen/).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属性等。