|
xuersweety 发表于 2012-1-10 21:17
你好,我运行了一下,一个数据都没有写入。
我又更新了一下文件。只要能将这个月的前一个月的数据写入对 ... - Sub Macro1() '引用Microsoft ActiveX Data Objects 2.x Library
- Dim cnn As New ADODB.Connection
- Dim rs As ADODB.Recordset
- Dim SQL$, arr, i&, j&, lr&, lc%, s$, t$
- arr = [a1].CurrentRegion
- lr = UBound(arr)
- lc = UBound(arr, 2)
- t = "[Feuil1$" & [a3].Resize(60000, lc).Address(0, 0) & "]"
- cnn.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 12.0;hdr=no';data source=" & ThisWorkbook.Path & "\write.xlsx"
- For i = 3 To lr
- SQL = "select * from " & t & " where f1='" & arr(i, 1) & " '"
- Set rs = New ADODB.Recordset
- rs.Open SQL, cnn, 1, 3
- If rs.RecordCount Then
- s = ""
- For j = 2 To lc
- s = s & "f" & j & "=" & arr(i, j) & " ,"
- Next
- SQL = "update " & t & " set " & Left(s, Len(s) - 1) & " where f1='" & arr(i, 1) & " '"
- cnn.Execute SQL
- End If
- Next
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码
|
|