本文介绍了将10个xls文件合并为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有10 xls报告,每列8列。
所有文件包含相同的列名。
我需要将它们合并到一个xls文件中。
需要帮助继续。
我尝试过的事情:
我用以下方法解决了链接
tps://www.codeproject.com/Tips/715976/Solutions-to-Merge-Multiple-Excel-Worksheets-int
Hi all
I have 10 xls report with 8 columns each.
All files contains same column names.
I need to merge them to a single xls file.
need help to proceed.
What I have tried:
I resolved using below link
tps://www.codeproject.com/Tips/715976/Solutions-to-Merge-Multiple-Excel-Worksheets-int
推荐答案
Sub ReadXLFiles()
'set a reference (in Tools / References) to Microsoft ActiveX Data Objects
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnect As String
Dim strSQL As String
Dim recCount As Long
Dim ws As Worksheet
Dim wsTgt As Worksheet
Dim strFileName As String
Dim strFilePath As String
Dim bNeedToWriteHeaders As Boolean
Dim rngTgt As Range
Dim c As Integer
On Error GoTo ErrorHandler
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set wsTgt = ActiveSheet
Set rngTgt = wsTgt.Range("A1")
' clear existing data
rngTgt.CurrentRegion.Clear
strFilePath = ActiveWorkbook.Path
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
strFileName = Dir(strFilePath & "\*.xls*")
strSQL = "SELECT * FROM [Sheet1
这篇关于将10个xls文件合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!