Sub PrintAll()
Const xDefaultPath = "d:\tmp\"
Const xFileSelector = "*.xls*"
Dim xFolderSelect As Variant
Dim xFolder As Variant
Dim xFileName As Variant
Dim xSheet As Worksheet
Dim xNoData As Boolean
Dim objShell As Variant
Dim kk As Long
Dim nn As Long
Dim xLast As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ThisWorkbook.Worksheets(1).UsedRange.Clear
ThisWorkbook.Worksheets(1).Cells(1, "A") = "ブック名"
ThisWorkbook.Worksheets(1).Cells(1, "B") = "シート名"
xNoData = True
Set objShell = CreateObject("Shell.Application")
Set xFolderSelect = objShell.BrowseForFolder(&O0, "処理対象フォルダを選択, Please!!", &H1 + &H10, xDefaultPath)
If xFolderSelect Is Nothing Then Exit Sub
' MsgBox xFolderSelect.Files.Count & "個のファイルがあります", vbInformation
xFolder = xFolderSelect.Items.Item.Path & "\"
'先頭のファイル名の取得
xFileName = Dir(xFolder & xFileSelector, vbNormal)
nn = 2
Do Until xFileName = Empty
Workbooks.Open xFolder & xFileName
kk = 0
For Each xSheet In Worksheets
'シートを印刷(印刷ボタンを押す)
xSheet.PrintOut
ThisWorkbook.Worksheets(1).Cells(nn, "A") = xFileName
ThisWorkbook.Worksheets(1).Cells(nn, "B").Offset(0, kk) = xSheet.Name
ThisWorkbook.Worksheets(1).Cells(nn + 1, "B").Offset(0, kk) = xSheet.Cells(1, "A")
xLast = xSheet.Cells(xSheet.Rows.Count, "A").End(xlUp).Row
ThisWorkbook.Worksheets(1).Cells(nn + 2, "B").Offset(0, kk) = xLast
kk = kk + 1
Next
xNoData = False
MsgBox "ファイル:" & ActiveWorkbook.Name & "(シート:" & kk & ")", vbInformation
nn = nn + 3
Workbooks(xFileName).Close False
NextFile:
xFileName = Dir()
Loop
If xNoData = True Then
MsgBox ("No Data Found!!")
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
お礼
丁寧にプログラムまで書いていただき本当にありがとうございました。