How to make toolbar button visible?

H

hstijnen

Hi,
I've hidden a toolbar button manually. Now I want to make it visible with VBA.
I have already som code:
For Each ctl In CommandBars("formatting").Controls
If ctl.caption = strCaption Then
ctl.visible = visible
End If
Next ctl

But it appears the looping is only through visible buttons, so my invisible
button is not found.
What can I do?

Thanks for help,

Henk
 
K

Klaus Linke

Hi Henk,

ctl.visible = True

Better use Option Explicit at the top of the module to avoid such typos.

Greetings,
Klaus
 
H

hstijnen

I'm sorry, Klaus,
That's not the problem. "visible" is a parameter of a function, wherewith I
wuold like to mke the button visible or invisible. The full code is:

Sub SetButtonVisible(caption As String, visible As Boolean)
For Each ctl In CommandBars("formatting").Controls
If ctl.caption = caption Then
ctl.visible = visible
End If
Next ctl
End Sub

The sub works ok for setting a button invisible. But when resetting visible
the button appears not in the collection
For Each ctl In CommandBars("formatting").Controls
So the question is how to get the invisible buttons in the collection.

Greetings,
Henk
 
K

Klaus Linke

So the question is how to get the invisible buttons in the collection.

Shouldn't make a difference whether they are visible or not.
Perhaps single-step, or try to put a
Debug.Print ctl.caption
in the loop to see if all controls are looped?
Or check CommandBars("Formatting").Controls.Count?

Regards,
Klaus
 

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