| 
    
     |  | ゆうゆうさん、こんにちは。 Jakaさん、おひさです。
 
 久しぶりに参加させて頂きます。
 FileSystemObjectを使ってみました。
 
 Sub aaa()
 Dim fName As String
 Dim fsoText As Object
 Dim i As Integer, j As Integer
 Dim lstFNo As Long, lstLine As Long
 lstFNo = 3 'ファイルの数
 lstLine = 4 '取得する行数
 For i = 1 To lstFNo
 'Bookと同じフォルダにTextファイルがあるとして
 fName = ThisWorkbook.Path & "\TXT" & i & ".txt"
 If Dir(fName) = "" Then Exit Sub 'ファイルが無い場合は終了
 Set fsoText = CreateObject("Scripting.FileSystemObject").OpenTextFile(fName, 1)
 Cells(i, 1).Value = Dir(fName) '1列目にファイル名
 For j = 2 To lstLine + 1
 Cells(i, j).Value = fsoText.ReadLine
 Next
 fsoText.Close
 Next
 Set fsoText = Nothing
 End Sub
 
 
 |  |