Sub ブック_INDEX() 'シートのINDEXを作成する。 Dim s As Worksheet Dim i As Integer Dim w_sheet As Worksheet '■■■■■■■■■■■■■■■■■ Application.DisplayAlerts = False Application.EnableEvents = False Application.ScreenUpdating = False Application.Calculation = xlCalculationManual '■■■■■■■■■■■■■■■■■ On Error Resume Next Sheets("INDEX").Delete On Error GoTo 0 Sheets.Add Before:=Sheets(1) Set s = ActiveSheet s.Name = "INDEX" s.Cells.ColumnWidth = 2 i = 2 For Each w_sheet In Sheets s.Cells(i, 1) = w_sheet.Index s.Cells(i, 3) = "'" & w_sheet.Name ActiveSheet.Hyperlinks.Add Anchor:=s.Cells(i, 3), Address:="", SubAddress:="'" & s.Cells(i, 3).Value & "'!A1", TextToDisplay:="'" & s.Cells(i, 3).Value s.Cells(i, 3).Font.Underline = xlUnderlineStyleNone
If w_sheet.Visible = xlSheetHidden Then s.Cells(i, 3).Interior.ColorIndex = 15 '灰色 End If s.Cells(i, 5).Value = w_sheet.Cells.SpecialCells(xlCellTypeLastCell).row s.Cells(i, 6).Value = w_sheet.Cells.SpecialCells(xlCellTypeLastCell).Column i = i + 1 Next w_sheet For Each w_sheet In Sheets If w_sheet.Name <> "INDEX" Then w_sheet.Activate w_sheet.Range("A1").Select End If i = i + 1 Next w_sheet Sheets("INDEX").Activate For Each w_sheet In Sheets w_sheet.Select Application.StatusBar = w_sheet.Name DoEvents ActiveWindow.LargeScroll ToLeft:=99 ActiveWindow.LargeScroll Up:=99 With w_sheet.PageSetup If .Zoom = False Then If .FitToPagesWide <> 1 Or .FitToPagesTall <> 1 Then .FitToPagesWide = 1 ' 横方向 1 ページに収める .FitToPagesTall = False ' 縦方向は制限しない(任意) End If End If End With
ActiveWindow.View = xlPageBreakPreview ActiveWindow.Zoom = 100 Next w_sheet
Application.StatusBar = "印刷設定中" DoEvents Dim ws As Worksheet Dim arr() Dim i1 As Long '--- 全シート名を配列に格納 --- ReDim arr(1 To ActiveWorkbook.Worksheets.Count) For i1 = 1 To ActiveWorkbook.Worksheets.Count arr(i1) = ActiveWorkbook.Worksheets(i1).Name Next i1 '--- 全シートを一括選択 --- ActiveWorkbook.Worksheets(arr).Select '--- 印刷設定を一発で適用 --- Dim topM As Double, bottomM As Double, leftM As Double, rightM As Double Dim headerM As Double, footerM As Double
topM = Application.CentimetersToPoints(2) bottomM = Application.CentimetersToPoints(1) leftM = Application.CentimetersToPoints(1) rightM = Application.CentimetersToPoints(1) headerM = Application.CentimetersToPoints(1) footerM = Application.CentimetersToPoints(0.5) With ActiveSheet.PageSetup
.Orientation = xlLandscape .PaperSize = xlPaperA4 .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = False .LeftHeader = "&F" .CenterHeader = "&A" .RightHeader = "ページ &P"
.topMargin = topM .bottomMargin = bottomM .leftMargin = leftM .rightMargin = rightM .HeaderMargin = headerM .FooterMargin = footerM
End With '--- 最初のシートだけ選択状態に戻す --- Worksheets(arr(1)).Select
Dim ws1 As Worksheet Dim totalPages As Long Dim thisPages As Long totalPages = 1 '最初のシートは1ページ目から Dim x As Integer x = 2 For Each ws1 In ActiveWorkbook.Worksheets 'シートの印刷ページ数を取得 thisPages = ws1.PageSetup.Pages.Count '開始ページ番号をに書き込む s.Range("D" & x).Value = totalPages x = x + 1 '累積ページを更新 totalPages = totalPages + thisPages Next ws1 With s .Range("A1").Value = "シート№" .Range("A1").HorizontalAlignment = xlRight .Range("C1").Value = "シート名" .Range("D1").Value = "ページ" .Range("D1").HorizontalAlignment = xlRight .Range("E1").Value = "行数" .Range("F1").Value = "列数" .Tab.ColorIndex = 3 .PageSetup.PrintArea = "A1:D" & .UsedRange.Rows.Count End With
s.Activate s.Cells.Font.Name = "Meiryo UI" s.Cells.EntireColumn.AutoFit Rows("2:2").Select ActiveWindow.FreezePanes = True Columns("C:C").Select Selection.AutoFilter s.Cells(1, 1).Select
'■■■■■■■■■■■■■■■■■ Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True Application.EnableEvents = True Application.DisplayAlerts = True Application.StatusBar = False '■■■■■■■■■■■■■■■■■
End Sub