1.功能介绍 本功能主要实现将同一个文件夹的相似Excel文件里的内容汇总到同一个EXCEL文件中。 2.代码实现 Sub ボタン3_Click() Dim dstSheet As Worksheet Set dstSheet = ThisWorkbook.Worksheets(1) Const Path As String = "D:\ou\Calibration\Result\" Dim buf As String Dim value As String Dim temp() As String '入力个所 Const prefix = "result_" Const center_str = "Yaw" Const cnsDIR = "\" + prefix + center_str + "*.csv" buf = Dir(Path & cnsDIR, vbNormal) Dim i As Long Do While buf <> "" i = i + 1 Dim srcBook As Workbook Set srcBook = Workbooks.Open(Path + buf) Dim srcSheet As Worksheet Set srcSheet = srcBook.Worksheets(1) dstSheet.Cells(10, i).value = srcSheet.Cells(1, 1) srcBook.Close False 'ファイル名を分割 temp = Split(buf, "_") value = Mid(temp(1), Len(center_str) + 1, Len(temp(1)) - Len(center_str) - 4) dstSheet.Cells(9, i).value = value buf = Dir() Loop End Sub
文章来源: https://blog.csdn.net/wangfengfan1/article/details/91397954