Skip to content

Instantly share code, notes, and snippets.

@skysan87
Last active March 29, 2023 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skysan87/343e5076f39f706ae7af3285ebcee018 to your computer and use it in GitHub Desktop.
Save skysan87/343e5076f39f706ae7af3285ebcee018 to your computer and use it in GitHub Desktop.
[VBA]開いているExcelブックのフォーカスをA1に揃えるマクロ
Public Sub SelectA1()
'描画停止
Application.ScreenUpdating = False
Dim firstIndex As Integer
firstIndex = 0
Dim Target As Worksheet
For Each Target In Worksheets
'Debug.Print target.Name
If Target.Visible = xlSheetVisible Then
If firstIndex = 0 Then
firstIndex = Target.Index
End If
Target.Select
Target.Cells(1, 1).Select
'表示倍率を変更
ActiveWindow.Zoom = 100
'スクロールをA1までする
Application.Goto Reference:=Target.Range("A1"), Scroll:=True
'表示を標準ビューにする
ActiveWindow.View = xlNormalView
End If
Next Target
Worksheets(firstIndex).Select
Application.ScreenUpdating = True
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment