Sub ADO_INPUT() '將記錄導(dǎo)入到excel中 Dim RS1 As Recordset Dim DB1 As Database Dim col As Integer Dim I As Integer 'On Error GoTo 1000 col = Sheet2.Range("A65535").End(xlUp).Row Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "backdatabase.accdb ") Set RS1 = DB1.OpenRecordset(Name:="aa", Type:=dbOpenDynaset) dim m as integer For I = 7 To col With RS1 .AddNew for m = 1 to 17 '如果你的數(shù)據(jù)庫中的數(shù)據(jù)跟excel都是按照順序來的,則用一個(gè)循環(huán)足以! .fields(m)=sheet2.cells(i,m) next .Update End With Next I RS1.Close '1000: MsgBox "找不到符合條件的記錄", 1 + 64, "系統(tǒng)提示" End Sub |
|