里面的原代码如下: Sub Add_Rcs() 'On Error Resume Next Dim New_Rsc(1 To 16) As Variant Dim i As Integer, j As Integer, k As Integer, iRows As Integer, n As Integer Dim mydata As String, SQL As String, mytable As String, myFieldList() As Variant Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset mydata = ThisWorkbook.Path & "\单据库2.mdb" mytable = "入库记录2" If Dir(mydata) = "" Then MsgBox "入库数据库不存在!请联系程序维护人!", vbExclamation, "无法连接数据库" Exit Sub End If '连接数据库 With cnn .Provider = "microsoft.jet.oledb.4.0" .Open mydata End With '打开“入库表” rs.Open mytable, cnn, adOpenKeyset, adLockOptimistic 'adLockBatchOptimistic or adLockOptimistic '取数据行 iRows = Sheets(1).[a65536].End(xlUp).Row For i = 1 To iRows - 1 '写数值到数据库 rs.AddNew For j = 1 To 16 rs.Fields(j - 1) = Sheet1.Cells(i + 1, j) 'rs.Update Next j Next i rs.UpdateBatch rs.Close cnn.Close Set cnn = Nothing: Set rs = Nothing MsgBox "数据写入数据库完毕!", vbOKOnly + vbInformation End Sub |