|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub CertificatestoAccess()
- Dim cnn As New ADODB.Connection
- Dim cat As New ADOX.Catalog
- Dim myData$, myFile, h$, tb1, s$
- myData = ThisWorkbook.Path & "\Data.accdb"
- myPath = ThisWorkbook.Path & ""
- myFile = Dir(myPath & "*拼单*.xls?")
- If myFile = "" Then
- MsgBox "无需更新", vbInformation, "提醒"
- Exit Sub
- End If
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & myData
- Do While myFile <> ""
- h = Right$(myFile, 4)
- If h = ".xls" Or h = "xlsx" Then
- cat.ActiveConnection = "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & myPath & myFile
- For Each tb1 In cat.Tables
- If tb1.Type = "TABLE" Then
- s = Replace(tb1.Name, "'", "")
- If Right(s, 1) = "$" Then
- cnn.Execute "insert into Certificates SELECT f1 as [ACC Number],f3 as [Certificates] from [Excel 12.0;hdr=no;Database=" _
- & myPath & myFile & "].[" & s & "E7:G] where f1 is not null"
- End If
- End If
- Next
- End If
- myFile = Dir()
- Loop
- Set cat = Nothing
- cnn.Close
- Set cnn = Nothing
- MsgBox "导入完成"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|