Sub get_file_sheet()
Dim fn(10000)
Dim sn(10000, 2)
Dim i As Long, j As Long, k As Long, x As Long
Dim mypath As String
Dim ext As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "フォルダを選択"
.AllowMultiSelect = False
If .Show = -1 Then
mypath = .SelectedItems(1)
Else
Exit Sub
End If
End With
Application.ScreenUpdating = False
fn(1) = Dir(mypath & "\", vbDirectory)
i = 1
Do
i = i + 1
fn(i) = Dir
Loop Until fn(i) = ""
x = 0
For j = 1 To i - 1
ext = Mid(fn(j), InStrRev(fn(j), ".") + 1, 3)
If ext = "xls" Then
Workbooks.Open Filename:=mypath & "\" & fn(j)
For k = 1 To Sheets.Count
sn(x, 1) = fn(j)
sn(x, 2) = Sheets(k).Name
x = x + 1
Next k
ActiveWorkbook.Close
End If
Next j
Columns("A:B").Select
Selection.ClearContents
Cells(2, 1) = "作業フォルダ"
Cells(3, 1) = mypath
Cells(4, 1) = "ファイル名"
Cells(4, 2) = "シート名"
x = 0
Do
Cells(x + 5, 1) = sn(x, 1)
Cells(x + 5, 2) = sn(x, 2)
x = x + 1
Loop Until sn(x, 1) = ""
Range("A1").Select
Application.ScreenUpdating = True
MsgBox "完了しました"
End Sub