[求助]数据从excel到access的转换问题
以下代码为excel到access的转换,请问有什么错误,应该如何改,谢谢Private Sub Command1_Click()
Dim cnn1 As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim i As Integer
Dim j As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim oldPointer As Integer 'used to save the current
Dim rPointer As Integer 'current saving record
Dim xlsPointer As Integer 'used to point out the position the current record saving
Set cnn1 = New ADODB.Connection
cnn1.Open "Provider=sqloledb;Data Source=TANGZL;Initial Catalog=pubs;User Id=sa;Password=sa;"
Set rs1 = New ADODB.Recordset
rs1.CursorType = adOpenKeyset
rs1.LockType = adLockOptimistic
rs1.Open "product", cnn1, , , adCmdTable
xlsPointer = 1 'the first line of Excel sheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open("D:\database\product.xls")
Set xlSheet = xlBook.Worksheets(1)
Hide
xlSheet.Columns = 6
xlSheet.Rows = 2
For i = 0 To xlSheet.Rows - 1
rs1.AddNew
For j = 0 To xlSheet.Columns - 1
rs1.Fields(i) = xlSheet.Cells(xlsPointer, i + 1)
Next j
xlsPointer = xlsPointer + 1
Next i
Set xlApp = Nothing
Set xlBook = Nothing
xlBook.Close
xlApp.Quit
End Sub