|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
wang94103 发表于 2013-6-25 14:55
谢谢您这么快给我解答,谢谢!!基本实现了我的想法。但我还有几个问题请教:1、我原设想是在“录入”表录 ...
还是原来的想法吧,直接填写录入表。然后点按钮,分别录入各表,在录入之后自动清除录入表的内容。- Option Explicit
- Sub 录入()
- Application.ScreenUpdating = False
- Dim conn As Object, xrow As Long, i As Long, sqlstr$, sAdress$, sht As Worksheet
- Set conn = CreateObject("adodb.connection")
- conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
- sAdress = Range("a3", Cells(Rows.Count, "i").End(xlUp)).Address(0, 0)
-
- For Each sht In Worksheets
- If sht.Name <> "录入" Then
- sqlstr = "Select 日期,摘要,收入数量,发出数量,库存,备注,批号,小号 from [录入$" & sAdress & "] where 产品 = '" & sht.Name & "'"
-
- With sht
- xrow = .[a65535].End(xlUp).Row + 1
- .Range("a" & xrow).CopyFromRecordset conn.Execute(sqlstr)
- End With
- End If
- Next
- Sheets("录入").Activate
- Range(Range("a4"), Cells(Rows.Count, "i")).ClearContents
- Set conn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|