|
楼主 |
发表于 2014-12-19 20:49
|
显示全部楼层
我在网上找了一个样例,希望老师帮我改造改造,改造成我需要的,非常感激
Private Sub CommandButton1_Click()
Cells.ClearContents
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=MS Access Database;DBQ=" & ThisWorkbook.Path & "\db1.mdb;;;UID=admin;PWD=123", Destination:=Range("A1"))
.CommandText = "SELECT * FROM yo"
.Refresh BackgroundQuery:=False
End With
End Sub
Private Sub CommandButton2_Click()
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase(ThisWorkbook.Path + "\db1.mdb ", False, False, ";Pwd=123")
db.Execute ("delete * from yo")
For i = 3 To [a2].End(xlDown).Row
Sql = "INSERT INTO yo(name,sex) values ('" & Cells(i, 1) & "','" & Cells(i, 2) & "')"
db.Execute (Sql)
Next
MsgBox "D′èëêy¾Y" & [a2].End(xlDown).Row - 1 & "DD"
End Sub
|
|