|
Sub shisi()
Dim conn As Object, sql$
pf$ = ThisWorkbook.Path & "\物控中心.accdb"
Set conn = CreateObject("adodb.connection")
If Application.Version * 1 <= 11 Then
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;data source=" & pf
ElseIf Application.Version * 1 >= 12 Then
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;data source=" & pf
End If
r = Range("a65536").End(xlUp).Row
arr = Range("a2", Cells(r, "t"))
For Each Rg In [a1:t1]
s = s & "," & "`" & Rg.Text & "`"
Next
s = Mid(s, 2)
For x = 1 To UBound(arr)
For j = 3 To UBound(arr, 2)
If Len(arr(x, j)) Then
sr = sr & "," & arr(x, j)
Else
sr = sr & "," & "Null"
End If
Next
sr = Mid(sr, 2): t = "#" & arr(x, 1) & "#"
sr = t & "," & "'" & arr(x, 2) & "'" & "," & sr
sql = "Insert into 物流计划 (" & s & ") VALUES(" & sr & ")"
conn.Execute sql: sr = ""
Next
conn.Close
Set conn = Nothing
MsgBox "成功录入数据库"
End Sub |
评分
-
1
查看全部评分
-
|