combo, thanks for the response. I think that is something like the approach I need, but it is not right yet.
In SetCommandBar, you delete the existing buttons on the toolbar - I do not want to do this and I don't understand why I would need to.
In the second, you use the .state property. I tried that, but found that the state is always "up" when the button is pressed, regardless of what .state I set in the code.
Perhaps I'd best expand briefly:
I've written a workbook-based tool. It allows the user to create a particular type of diagram. It has a toolbar with 14 buttons. Several of these allow the user to add shapes to the diagram. The user will want to enter text into the shapes he adds. He can do this manually, in the shape itself, but when the diagram is zoomed out to see the whole, the text is too small to read. So, as part of the function of the shape creation buttons, I've included a short procedure where a userform is presented on which there is a text box the user can use to enter the text.
However, if he is only working in a small section of the diagram this is not necessary and requires more activity for the user than if he entered the text directly. So, what I need is a global boolean which the shape-drawing routines can see to determine whether to include the useform section or not.
That is where this button comes in. I have added the required button to the toolbar, created an appropriate face for it and pointed it at the appropriate sub. What I want the sub to do is:
toggle the UseUserForm boolean
toggle the appearance of the button (i.e. latch it in "depressed" state when it is clicked then "release" it when it is clicked again - pretty much like the standard buttons "format painter" button, or "select objects".
I did try your changebutton code method, but, as I say neither the appearance of the button nor the .state property seem to change.
The code I presented in my second post does what I need, but only if I use a text button. I'd rather use an icon.
I could of course use .faceid in the same way I use the text (to display the state to the user and to determine the current state) but I don't know how to define a faceID for my custom image. What I want to be able to do is capture the image of the depressed button and make it stay that way rather than releasing after clicking. I thought .state would do that, but it does not seem to do so.
Here is the code I used to try the .state manipulation:
Code:
Sub SetText()
With Commandbars("QASI").controls(Application.Caller(1)))
If UseUserForm then
UseUserForm = False
.state = msoButtonUp
.TooltipText = "Inc Text"
Else
UseUserForm = True
.state = msoButtonDown
.TooltipText = "No Text"
End If
End With
End Sub
This works, in the sense that the state and the tooltip change, but the appearance of the button does not.
Tony