|
>ブックのシート名は規定のsheet1だったり1月だったりです。
各ブックのシートを何を条件に指定すればよいのでしょうか?
各ブックのシートは1つだけでしょうか?
だとすれば、Worksheets(1) で指定できますが・・・
Sub Sample()
Dim myObj As Object
Dim myFileName As String
Dim myDir As String
Dim mySheet As Variant
Application.ScreenUpdating = False
With ThisWorkbook.ActiveSheet
Set myObj = CreateObject("Shell.Application"). _
BrowseForFolder(0, "フォルダを選択してください", 0)
If myObj Is Nothing Then Exit Sub
myDir = myObj.Items.Item.Path & "\"
myFileName = Dir(myDir & "*", vbHidden + vbSystem)
Do
Workbooks.Open myDir & myFileName
For Each mySheet In ActiveWorkbook.Sheets
.Cells(Rows.Count, 1).End(xlUp).Offset(1).Value = myFileName
.Cells(Rows.Count, 2).End(xlUp).Offset(1).Value = mySheet.Name
Next mySheet
Workbooks(myFileName).Close False
myFileName = Dir()
Loop Until myFileName = vbNullString
.Range("A1").Value = "ファイル名"
.Range("B1").Value = "シート名"
.Columns("A:B").AutoFit
Application.ScreenUpdating = True
End With
End Sub
|
|