|
ExcelVBA代码请参考:- Sub addRecords() '从工作表中向数据表添加纪录
- Dim cnn As New ADODB.Connection
- Dim SQL As String
- Columns("A:B").NumberFormatLocal = "@"
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\9999.accdb"
- SQL = "DELETE FROM 表1 A WHERE EXISTS(SELECT * FROM [Excel 12.0;Database=" & ThisWorkbook.FullName & "].[" & ActiveSheet.Name & "$" _
- & Range("a1").CurrentRegion.Address(0, 0) & "] WHERE 成品编号=A.成品编号)"
- cnn.Execute SQL '先删除可能存在的与工作表中相同的"成品编号"记录
- SQL = "INSERT INTO 表1 SELECT * FROM [Excel 12.0;Database=" & ThisWorkbook.FullName & ";].[" & ActiveSheet.Name & "$" _
- & Range("a1").CurrentRegion.Address(0, 0) & "]"
- cnn.Execute SQL
- MsgBox "纪录添加成功。", vbInformation, "添加纪录"
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|