ファイルの件数は最高で99件です
01-99
▽1
●
oil999 ●100ポイント ベストアンサー |
こんな感じでどうでしょう。
"C:\test\" にあるCSVファイルのみを連結して、"C:\test\test.csv" に出力します。
ターゲットのフォルダ、拡張子、出力先ファイル名は、マクロの最後の Call hogeCoupling の引数を変更することで対応できます。
Option Explicit '1ファイル処理 Sub appendFile(path As String, fname As String, outfname As String) Dim buf As String, idx As String Dim fname2 As String, fname3 As String Dim x As Long 'CSVファイル読み込み&書き込み fname2 = path & fname Open fname2 For Input As #1 Open outfname For Append As #2 Do Until EOF(1) Line Input #1, buf Print #2, buf Loop Close #2 Close #1 End Sub 'ファイル探索+処理実行 Sub hogeCoupling(path As String, ext As String, outfname As String) Dim fcol As Object, re As Object Dim flist As Variant, remat As Variant Dim pat As String, fname As String Dim n As Long '処理対象ファイル探索+処理実行 Set fcol = CreateObject("Scripting.FileSystemObject").GetFolder(path).Files Set re = CreateObject("VBScript.RegExp") pat = "\." & ext & "$" With re .Pattern = pat .IgnoreCase = True .Global = True For Each flist In fcol Set remat = .Execute(flist.name) If remat.Count > 0 Then Call appendFile(path, flist.name, outfname) End If Next flist End With Set re = Nothing Set fcol = Nothing End Sub Sub main() Call hogeCoupling("C:/test/", "csv", "C:/test/test.csv") End Sub