循环文件夹汇总所有发票开具Excel文件数据
作者:互联网
不打开Excel文件提取数据?
Dim a As String, n As Integer, wbs As Workbook
ThisWorkbook.Sheets(1).Cells.Clear
a = Dir(ThisWorkbook.Path & "\*.xlsx")
'Application.DisplayAlerts = False
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
arr = Array("发票代码", "发票号码", "购方企业名称", "购方税号", "开票日期", "商品名称", "规格", "单位", "数量", "单价", "金额", "税率", "税额", "税收分类编码")
ThisWorkbook.Sheets(1).Range("A1:N1") = arr
x = 2
Do While a <> ""
If a <> "开票汇总.xlsm" Then
Workbooks.Open ThisWorkbook.Path & "\" & a
endrow = Range("O65536").End(xlUp).Row
strTable = "[sheet1$A4:R" & endrow & "]"
For i = 5 To endrow
商品 = Range("J" & i)
Next
Workbooks(a).Close
con.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 8.0;hdr=yes;imex=1';data source=" & ThisWorkbook.Path & "/" & a
strSQL = "select 发票代码, 发票号码, 购方企业名称, 购方税号, 开票日期, 商品名称, 规格, 单位, 数量, 单价, 金额, 税率, 税额, 税收分类编码 from " & strTable & " where 商品名称<>'小计'"
Set rs = con.Execute(strSQL)
ThisWorkbook.Sheets(1).Range("A" & x).CopyFromRecordset rs
a = Dir
x = ThisWorkbook.Sheets(1).Range("K65536").End(xlUp).Row + 1
con.Close
End If
Loop
'Application.DisplayAlerts = False
Set con = Nothing
Set rs = Nothing
标签:ThisWorkbook,rs,Excel,Range,文件夹,开具,Sheets,购方,con 来源: https://www.cnblogs.com/ttsysy/p/16387589.html