|
Sub Macro1()
Dim cnn As Object, SQL$
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cnn.Open "Provider = Microsoft.Jet.Oledb.4.0;Extended Properties =Excel 8.0;Data Source =" & ThisWorkbook.Path & "\备份.xls"
SQL = "select* from [Sheet1$]"
rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
While Not rs.EOF
For j = 1 To rs.Fields.Count
rs.Fields(j - 1) = Null
Next j
rs.Update
rs.MoveNext
Wend
End If
' Exit Sub
' SQL = "insert into [Sheet1$] select * from [Excel 8.0;Database=" & ThisWorkbook.FullName & "].[Sheet1$]"
' cnn.Execute SQL
' MsgBox "数据已经添加到数据库!", vbInformation, "添加数据"
cnn.Close
Set cnn = Nothing
End Sub
上面的代码,当全部有数据时能全部更新为空,但当有间隔的数据时就不能全部更新为空了,请教一下需要怎么修改才能全部清空数据,谢谢! |
|