Code to Add Toolbar Button


Posted by JAF on May 31, 2000 1:42 AM

I have the following code which adds and removes the Web "Back" button to the end of my Standard Toolbar

ADD...
Application.CommandBars("Standard").Controls.Add Type:=msoControlButton, Id:=1017, Before:=25

REMOVE...
Application.CommandBars("Standard").Controls(25).Delete

The problem I have is that the Standard Toolbars of my users have been customised (which they need to keep) so each user's Standard Toolbar has a different number of existing toolbar buttons - mine has 24 (hence 25 in the above code) but other users have different numbers of toolbar icons.

Is there any way to add the Web "Back" button to the END of the Standard Toolbar (and also remove it later) irrespective of the number of buttons on the toolbar? I have a current compromise whereby I can add/remove the button as the first item on the toolbar, but I want it at the end.

Any help appreciated.


JAF



Posted by Ivan Moala on May 31, 2000 2:05 AM

Jaf
Try;

Dim Bf As Integer

Sub MoveToEnd()

Bf = Application.CommandBars("Standard").Controls.Count + 1
Application.CommandBars("Standard").Controls.Add Type:=msoControlButton, Id:=1017, Before:=Bf

End Sub

Sub Remove()
Bf = Application.CommandBars("Standard").Controls.Count
Application.CommandBars("Standard").Controls(Bf).Delete
End Sub

Ivan