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!

Objects 1

Status
Not open for further replies.

Tronsliver

Technical User
Sep 19, 2000
120
US
I built two dynamically added toolbars that are developed under the auto_activate command. Here is the code for sheet1:

Public Sub AutoRunSheet1()
Toolbars.Add "ClearTools1"
Toolbars("ClearTools1").Visible = True
Toolbars("ClearTools1").Position = xlLeft
End Sub

When I switch to sheet2 I deactivate the toolbars with this command:

Public Sub AutoCloseSheet1()
Toolbars("ClearTools1").Delete
End Sub

I then add another toolbar with this on sheet2:

Public Sub AutoRunSheet2()
Toolbars.Add "ClearTools2"
Toolbars("ClearTools2").Visible = True
Toolbars("ClearTools2").Position = xlLeft
End Sub

and when switching back to sheet1 I deactivate sheet2 with this:

Public Sub AutoCloseSheet2()
Toolbars("ClearTools2").Delete
End Sub

OK I hope I didn't make everyone dizzy :) This works great until I attempt to close the file without deactivating the toolbar. What happens is when I reopen, the program tries to again build a toolbar that is already in existence and gives me an error code.

I want to test to see if the toolbar is in existence upon closing the file, and if so, delete it before closing. I want to put the code in this procedure:

Public Sub Auto_Close()
If Toolbars("ClearTools1") = True Then
Toolbars("ClearTools1").Delete
Else
If Toolbars("ClearTools2") = True Then
Toolbars("ClearTools2").Delete

End If
End If
End Sub


What I'm attempting to do is check for an active toolbar and if "true" delete before closing the file. The code in the Procedure above does not work. Appreciate some suggestions..thank you
 
Hi,

Try this...
Code:
For Each Toolbar in ActiveWorkbook.Toolbars
   Select Case Toolbar.Name
      Case "ClearTools1", "ClearTools2"
         Toolbar.Delete
   End Select
Next
Hope this helps :) Skip,
metzgsk@voughtaircraft.com
 
Skip,

This didn't work I received the error message:

Object doesn't support this property or method..error 438
 
Hi,

Use...
Code:
For Each Toolbar In Toolbars
sorry :) Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top