Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add/remove toolbars with code (excel 5)

Status
Not open for further replies.
Jun 6, 2001
26
AU
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top