|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下,供参考:
- Sub 获取数据()
- Application.ScreenUpdating = False
- Dim SQL As String, sht As Worksheet
- Dim Cnn As Object: Set Cnn = CreateObject("ADODB.Connection")
- Cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\生产数据库.accdb"
- Dim mRst As Object: Set mRst = CreateObject("Adodb.RecordSet")
- SQL = "Select 序号,日期,产品编码,LOTNO,卷带数量 From 卷带生产"
- Set mRst = Cnn.Execute(SQL)
- With Worksheets("卷带生产")
- .Activate
- .Rows("2:1048576").ClearContents
- .Range("A2").CopyFromRecordset mRst
- End With
- ' ----
- For Each sht In Sheets
- If sht.Name <> "卷带生产" And sht.Name <> "录入" Then
- SQL = "Select * From " & sht.Name
- Set mRst = Cnn.Execute(SQL)
- With sht
- .Activate
- .Rows("2:1048576").ClearContents
- .Range("A2").CopyFromRecordset mRst
- End With
- End If
- Next
- Cnn.Close: Set Cnn = Nothing: Set mRst = Nothing
- Application.ScreenUpdating = True
- MsgBox "ok"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|