|
请把每个工作表的第3列“单价”设置为“数值”格式
在1工作簿更新后中执行:
Private Sub CommandButton1_Click() '引用Microsoft ActiveX Data Objects 2.8
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim arr, strSql As String, i As Long
arr = Range("A2:C" & Range("A65536").End(xlUp).Row).Value
On Error Resume Next
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Application.ScreenUpdating = False
wk = Dir(ThisWorkbook.Path & "\*.xls")
While wk <> ""
If wk <> ThisWorkbook.Name Then
cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=no';data source=" & ThisWorkbook.Path & "\" & wk
For i = 1 To UBound(arr)
strSql = "update [Sheet1$a2:c65536] set f3 =" & arr(i, 3) & " where f1='" & arr(i, 1) & " ' And f2 = '" & arr(i, 2) & " '"
rs.Open strSql, cnn, adOpenKeyset, adLockOptimistic
Next
cnn.Close
End If
wk = Dir()
Wend
Application.ScreenUpdating = True
End Sub |
|