Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim sql As String
Private Sub Form_Load()
On Error Resume Next
strName = "d:\vbalx\excela.xls" 'EXCEL文件名
strSheetName = "sheet1" 'EXCEL表名
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & strName & ";Extended Properties='Excel 8.0;HDR=Yes'" '连接EXCEL文件
sql = "select * from [" & strSheetName & "$]" '
End Sub
这代码可不可以用下面的代码替换
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = CreateObject("excel.application")
Set xlbook = xlApp.Workbooks.Open("d:\vbalx\excela.xls")
Set xlsheet = xlbook.Worksheets(1)
xlApp.Quit
Set xlApp = Nothing
End Sub
谢谢