はじめに
Excelの資料作成の際の見た目をきれいにするためのマクロを作成しました。
作成したマクロ
見た目をきれいにしたいExcelファイルが配置されているパスにxlsmファイルを用意して、こちらのマクロを貼り付けて実行します。
Sub SetZoomAndMoveToA1ForAllSheetsInAllFiles()
Dim folderPath As String
Dim fileName As String
Dim wb As Workbook
Dim ws As Worksheet
Dim currentWorkbookPath As String
' 現在のExcelファイルのパスを取得
currentWorkbookPath = ThisWorkbook.Path
' フォルダパスを設定
folderPath = currentWorkbookPath & "\"
' フォルダ内のすべてのExcelファイルを取得
fileName = Dir(folderPath & "*.xlsx")
Do While fileName <> ""
' 各ファイルを開く
Set wb = Workbooks.Open(folderPath & fileName, IgnoreReadOnlyRecommended:=True)
' 各シートに対して操作を実行
For Each ws In Worksheets
' 表示しているシートを対象
If ws.Visible = True Then
ws.Select
Range("A1").Select
' 表示位置を左上端に移動
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
' 表示倍率を100%に戻す
ActiveWindow.Zoom = 100
End If
Next ws
' 最後に1シート目に移動
wb.Sheets(1).Select
' ファイルを保存して閉じる
wb.Save
wb.Close
' 次のファイルに進む
fileName = Dir
Loop
MsgBox "完了しました"
End Sub
このマクロで行う編集内容
■編集対象
このマクロを実行するxlsmファイルと同じパスにあるExcelファイル(*.xlsx)
■編集内容
・すべてのシートに対して、表示率100%にして、A1セルに移動させる(非表示シートは除く)
・最後に1シート目に移動して保存する
■備考
強制的に編集し、保存するので
読み取り専用を促すメッセージは無視されて実行される
最後に
複数のExcelファイルの見た目を整えるときは、こちらのマクロ使ってみてください!