|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
在本机的文件上可以更新
Sub ts()
Dim cnn, sql$, myFile$, rs
Dim s1
Dim i As Long, j As Long, lMaxNum As Long
Set s1 = ThisWorkbook.Sheets("订单完成数")
s1.Select
i = 18 '本地订单起始行
lMaxNum = s1.Range("A18").End(xlDown).Row
arrMy = s1.Range(Cells(i, 1), Cells(lMaxNum, 5))
Dim STR
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
'cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=\\smt车间服务器\SMT\数据库\订单完成.xlsx"
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=D:\Cprogram\ACCESS\新建文件夹\订单完成.xlsx"
' sql = "UPDATE [订单完成数$] SET 订单号=订单号+1,贴片=贴片+1"
'
'For I = 1 To UBound(ARR)
'If STR = ARR(I, 1) Then
'sql = "UPDATE [订单完成数$] WHERE 订单号=str ,贴片=2222"
rs.Open "select * from [sheet1$]", cnn, adOpenKeyset, adLockOptimistic
For j = 1 To lMaxNum - i + 1
rs.Find "订单号=" & arrMy(j, 1)
If Not rs.EOF Then '订单已存在,更新
rs.Fields(1) = arrMy(j, 2)
rs.Fields(2) = arrMy(j, 3)
rs.Fields(3) = arrMy(j, 4)
rs.Fields(4) = arrMy(j, 5)
rs.Update
Else '订单不存在已存在,新建
rs.AddNew
rs.Fields(0) = arrMy(j, 1)
rs.Fields(1) = arrMy(j, 2)
rs.Fields(2) = arrMy(j, 3)
rs.Fields(3) = arrMy(j, 4)
rs.Fields(4) = arrMy(j, 5)
rs.Update
End If
Next j
'Set rs = cnn.Execute(sql)
MsgBox "数据更新成功!"
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
评分
-
1
查看全部评分
-
|