Sub auto_open()
ReDim 覚え(CommandBars.Count)
インデックス = 0
For Each 各バー In CommandBars
If 各バー.Visible Then '表示されていれば
インデックス = インデックス + 1
覚え(インデックス) = 各バー.Name '名前
End If
Next
'
MsgBox "表示中のコマンドバーの数: " & インデックス & vbCr & "非表示にします"
For I = 1 To インデックス
名前 = 覚え(I)
If "Worksheet Menu Bar" = 名前 Then
CommandBars(名前).Enabled = False '非表示にする
Else
CommandBars(名前).Visible = False
End If
Next
'
数式バーの現状 = Application.DisplayFormulaBar
MsgBox "数式バーの現状: " & 数式バーの現状 & " (現状に拘らず非表示にします)"
Application.DisplayFormulaBar = False
End Sub
ブックを閉じるときにコマンドバーと数式バーの表示を復元するマクロ
(中身のコードは本と同じです。)
Sub auto_close()
MsgBox "戻します"
Application.ScreenUpdating = False '画面を更新しない
For I = 1 To インデックス
名前 = 覚え(I)
If "Worksheet Menu Bar" = 名前 Then
CommandBars(名前).Enabled = True '表示する
Else
CommandBars(名前).Visible = True
End If
Next
Application.DisplayFormulaBar = 数式バーの現状
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayWorkbookTabs = True
End With
Application.DisplayFormulaBar = 数式バーの現状
End Sub