Identifying a button on a toolbar

P

Paul

How do I find out whether a specific button exists on the visible Standard
toolbar ?

I want to add a specific extra button, but need to determine whether it
already exists on the toolbar.


--
 
C

Chip Pearson

You can use code similar to the following.

If you used the Tag property when you created the control, you can
find it with FindControl searching for the Tag.

Dim C As Office.CommandBarControl
On Error Resume Next
Err.Clear
Set C = Application.CommandBars.FindControl(Tag:="your tag")
If Not C Is Nothing Then
Debug.Print "control exists"
Else
Debug.Print "control does not exist"
End If


If you didn't use the Tag property, you can look at the Caption that
was assigned to the button.

Dim C As Office.CommandBarControl
On Error Resume Next
Err.Clear
Set C = Application.CommandBars("Standard").Controls("Caption")
If Not C Is Nothing Then
Debug.Print "control exists"
Else
Debug.Print "control does not exist"
End If

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top