'引用 ADO 和 ADOX
'引用 ADO: Microsoft ActiveX Data Objects 2.6 Library
'引用 ADOX: Microsoft ADO Ext. 2.6 for DDL ans Security
Dim adoConnection As New ADODB.Connection
'OLE DB + ODBC Driver 方式:
'adoConnection.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=e:\temp\book2.xls"
'Microsoft.Jet.OLEDB.4.0 方式,(建议)
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\book1.xls;Extended Properties='Excel 8.0;HDR=Yes'"
Dim adoCatalog As New ADOX.Catalog
Set adoCatalog.ActiveConnection = adoConnection
Dim i As Long
For i = 0 To adoCatalog.Tables.Count - 1
Debug.Print adoCatalog.Tables.Item(i).Name
Next i
'引用 ADO: Microsoft ActiveX Data Objects 2.6 Library
'引用 ADOX: Microsoft ADO Ext. 2.6 for DDL ans Security
Dim adoConnection As New ADODB.Connection
'OLE DB + ODBC Driver 方式:
'adoConnection.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=e:\temp\book2.xls"
'Microsoft.Jet.OLEDB.4.0 方式,(建议)
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\book1.xls;Extended Properties='Excel 8.0;HDR=Yes'"
Dim adoCatalog As New ADOX.Catalog
Set adoCatalog.ActiveConnection = adoConnection
Dim i As Long
For i = 0 To adoCatalog.Tables.Count - 1
Debug.Print adoCatalog.Tables.Item(i).Name
Next i
Dim ExcelApp As Object Dim sheet As Object Set ExcelApp = CreateObject("excel.application")
'ExcelApp.Visible = True
ExcelApp.Workbooks.Open ("c:\1.xls")
For Each sheet In ExcelApp.Workbooks("1.xls").Worksheets
MsgBox sheet.Name
Next
ExcelApp.Quit
Set ExcelApp = Nothing
Set sheet = Nothing
EndEnd Sub关于Excel自动化操作的更多例程,请参考以下文章:ID: Q253235 FILE: OFFAUTMN.EXE Discusses Office 97 and 2000 Automation [OffDev]
http://support.microsoft.com/support/kb/articles/q253/2/35.asp
-微软全球技术中心 桌面产品技术支持立即参加微软认证的"最有价值专家"评选,赢取价值万元以上的丰富奖品!详情参见(http://www.csdn.net/expert/Topic/456/456919.shtm)
本贴子以"现状"提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。