tektripper
MIS
I am writing an application in MS Excel 5 and am trying to write some code that will remove all standard toolbars upon startup and then restore them upon closing the workbook. In excel 5 there is no such thing as a command bars collection just separate 'Menubars' and 'Toolbars' collections. The code I am using stores the names of the visible toolbars in an array and then hides them. Upon closure of the workbook I want the code to cycle through the array and make these toolbars visible. I have declared my array as a public variable at the top of the module but unfortunately the contents of the array disappear after the code runs. The code I am using is as follows....
Option Base 1
Public myOldbars() As String
Sub SetToolbars(State)
Dim tbarsCount As Integer
tbarsCount = Application.Toolbars.Count
ReDim Preserve myOldbars(1 To tbarsCount)
State = xlOff
If State = xlOn Then
For Each myBar In Application.Toolbars
If myBar.Visible Then
x = x + 1
myOldbars(x) = myBar.Name
myBar.Visible = False
End If
Next myBar
Else
For i = 1 To tbarsCount
ToolbarName = myOldbars(i)
Application.Toolbars(ToolbarName).Visible = True
Next
End If
End Sub
Thanks for any help somebody can provide.
Option Base 1
Public myOldbars() As String
Sub SetToolbars(State)
Dim tbarsCount As Integer
tbarsCount = Application.Toolbars.Count
ReDim Preserve myOldbars(1 To tbarsCount)
State = xlOff
If State = xlOn Then
For Each myBar In Application.Toolbars
If myBar.Visible Then
x = x + 1
myOldbars(x) = myBar.Name
myBar.Visible = False
End If
Next myBar
Else
For i = 1 To tbarsCount
ToolbarName = myOldbars(i)
Application.Toolbars(ToolbarName).Visible = True
Next
End If
End Sub
Thanks for any help somebody can provide.