G
Geo Siggy
Hello,
I tried the following code (I get it from somebody, don't remember wh
…) to hide the normally used commandbars when entering an applicatio
and reinstall the same used commandbars again when leaving the program
The hiding works fine, but when leaving the application, the followin
message comes:
"Runtime error 9, Index outside valid array."
Whats wrong with the code.
The code:
Public arrayCB As Variant
Private Sub Workbook_Open()
Dim myCB As CommandBar
Dim ii As Long
ReDim arrayCB(0)
For Each myCB In Application.CommandBars
If myCB.Visible Then
ReDim Preserve aryCBs(ii)
arrayCB(ii) = myCB.Name
myCB.Visible = False
ii = ii + 1
End If
Next myCB
Application.CommandBars("Worksheet Menu Bar").Visible = False
With Application
.DisplayFormulaBar = False
.DisplayStatusBar = False
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ii As Long
For ii = LBound(arrayCB) To UBound(arrayCB)
Application.CommandBars(arrayCB(ii)).Visible = True
Next ii
End Sub
… thanks Sigg
I tried the following code (I get it from somebody, don't remember wh
…) to hide the normally used commandbars when entering an applicatio
and reinstall the same used commandbars again when leaving the program
The hiding works fine, but when leaving the application, the followin
message comes:
"Runtime error 9, Index outside valid array."
Whats wrong with the code.
The code:
Public arrayCB As Variant
Private Sub Workbook_Open()
Dim myCB As CommandBar
Dim ii As Long
ReDim arrayCB(0)
For Each myCB In Application.CommandBars
If myCB.Visible Then
ReDim Preserve aryCBs(ii)
arrayCB(ii) = myCB.Name
myCB.Visible = False
ii = ii + 1
End If
Next myCB
Application.CommandBars("Worksheet Menu Bar").Visible = False
With Application
.DisplayFormulaBar = False
.DisplayStatusBar = False
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ii As Long
For ii = LBound(arrayCB) To UBound(arrayCB)
Application.CommandBars(arrayCB(ii)).Visible = True
Next ii
End Sub
… thanks Sigg