'---------将所有的Excel对象都设置成万能的Object类型-----
Dim xlApp As Object '引用了 Microsoft Excel 14.0就会出现这个对象
Dim xlWbk As Object
Dim xlWsh As Object
Dim Rng As Object
Dim rsNum As Integer
'-----------定义DAO的对象用于创建DAO记录集--------------
Dim rst As New ADODB.Recordset
Dim i As Integer
Dim cnn As Object
'-------------打开记录集
'Set rst = CreateObject("adodb.recordset")
'Set cnn = CurrentProject.Connection
Set rst = CreateObject("adodb.recordset")
Set cnn = CurrentProject.Connection
rst.CursorLocation = 3
rst.Open strExcel, cnn, 1, 1
' rst.Open strExcel, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
'------打开Excel表格-------
Set xlApp = GetObject(, "Excel.Application")
xlApp.Visible = True
Set xlWbk = xlApp.Workbooks.Add
Set xlWsh = xlWbk.Worksheets(1)
xlWsh.Activate
Create:
If Err = 429 Then
'--------------关键是这条语句,类似创建引用
Set xlApp = CreateObject("Excel.Application")
Resume Next
End If
用后期绑定的方式创建引用
最新推荐文章于 2022-03-31 18:58:49 发布