|
Sub a()
'引用dao 3.6
Dim myDatabase As DAO.Database
Dim myDataTable As DAO.TableDef
Dim myDatabaseName As String
Dim myDataTableName As String
Dim myIndex As DAO.Index
myDatabaseName = ThisWorkbook.Path & "\测试.mdb"
myDataTableName = "数据"
On Error Resume Next
Kill myDatabaseName
On Error GoTo 0
Set myDatabase = CreateDatabase(myDatabaseName, dbLangGeneral)
Set myDataTable = myDatabase.CreateTableDef(myDataTableName)
Dim arr
arr = [a1].CurrentRegion
With myDataTable
Set f = .CreateField("序号")
f.Type = dbLong
f.Attributes = dbAutoIncrField
.Fields.Append f
For i = 2 To UBound(arr)
.Fields.Append .CreateField(arr(i, 1), arr(i, 2))
Next
End With
myDatabase.TableDefs.Append myDataTable
Set myDatabase = Nothing
Call hb
End Sub
Sub hb()
Dim myfile$, mypath$
mypath = ThisWorkbook.Path & "\"
myfile = Dir(mypath & "*.xlsx")
Dim Cnn As Object, rs As Object, SQL$, x As Integer, y As Integer, m As Integer, crr, brr(1 To 9999, 1 To 14)
Do While myfile <> ""
Set Cnn = CreateObject("ADODB.Connection")
Cnn.Open "Provider=Microsoft.ace.OleDb.12.0;Extended Properties='Excel 12.0;HDR=yes'; Data Source=" & mypath & myfile
SQL = "select * from [sheet1$A1:n] WHERE 收款方式 is not null "
Set rs = Cnn.Execute(SQL)
crr = rs.GetRows
For m = 0 To UBound(crr, 2)
x = x + 1
For y = 1 To UBound(crr) + 1
brr(x, y) = crr(y - 1, m)
Next
Next
myfile = Dir()
Loop
[d2:z9999].ClearContents
[d2].Resize(x, 14) = brr
Cnn.Close
Cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\测试.mdb;"
SQL = "select * FROM [Excel 12.0;HDR=YES;DATABASE=" & ThisWorkbook.FullName & "].[sheet1$d1:q] where 收款方式 is not null"
SQL = "INSERT INTO 数据 (收款方式,收款账号,收款日期,入账日期,收款编号,币种,收款金额,发票编号,客户名称,客户编号,匹配的订单号,订单金额,已核销金额,未核销金额) " _
& SQL
Cnn.Execute (SQL)
Cnn.Close
Set Cnn = Nothing
End Sub
范例.rar
(49.67 KB, 下载次数: 109)
|
|