0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Excel-A1セルに戻して終了するマクロ

Last updated at Posted at 2022-04-27

グループ化しているものは閉じる&フォント=Meiryo UIに変える&A1セルにカーソル戻す&100%表示にして保存して閉じるコード
(※ワークブック=1つの際のアプリケーションquitが働いていないためデバッグ中)

Sub 保存して閉じる()
'
' close Macro
' 画面更新をさせない(チカチカするため)
Application.ScreenUpdating = False
'
Dim ws As Worksheet
' 各シートを順番に見ていく
For Each ws In Worksheets
' シート保護されてるか確認
If ws.ProtectContents = True Then
'保護されてたら何もしない
Else
    ws.Activate
    ws.UsedRange.Select
' フォントを「Meiryo UI」に変える
    With ws.Cells.Font
           .Name = "Meiryo UI"
'もし英数字だけArialに変えたい場合、↓の1行のシングルクォーテーションをとってください
           '.Name = "Arial"
    End With
    
' カーソルをA1に移動
    ws.Select
    Range("A1").Select
' 表示位置を左上端に移動
    ActiveWindow.ScrollColumn = 1
    ActiveWindow.ScrollRow = 1
' 表示倍率を100%に戻す
    ActiveWindow.Zoom = 100


ws.Outline.ShowLevels rowLevels:=1, columnLevels:=1
End If
Next ws
' 1枚目のシートに移動
Sheets(1).Select
'画面更新を再開させておく
Application.ScreenUpdating = True
If Workbooks.Count > 1 Then
    ActiveWorkbook.Save
    ActiveWorkbook.Close
Else
    ActiveWorkbook.Save
    Application.Quit
End If
'
'
End Sub
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?