|
|
|
date: Mon, 30 Jan 2006 10:59:30 -0800,
group: microsoft.public.word.vba.customization
back
Re: Toggle Toolbar Button for Toggle Macro
"Klaus Linke" wrote:
> "sjane" wrote:
> > In Word I have several toggle macros that I run from toolbar buttons.
> > I would like them to behave like the Word Bold, Underline, etc., toolbar
> > buttons - change depending on whether the button is depressed or not.
> > Can anyone help me with VBA code to do that? Thanks in advance.
> >
> > Sjane
>
>
> Hi Sjane,
>
> Look at the help for the State property of the CommandBarButton object.
>
> Regards,
> Klaus
>
> Klaus - thank you for your response. I spent some time reading up on the "state" property and tried to test out the example code given in the VBA help but didn't get very far - got an error in code below at second line "Expected:=" - do you have any other suggestions I can look into? Thanks in advance.
Set myBar = CommandBars _
.Add(Name:="Custom", Position:=msoBarTop, _
Temporary:=True)
With myBar
.Controls.Add Type:=msoControlButton, ID:=1
.Controls.Add Type:=msoControlButton, ID:=2
.Visible = True
End With
Set myControl1 = CommandBars("Custom").Controls(1)
myControl1.State = msoButtonUp
Set myControl2 = CommandBars("Custom").Controls(2)
myControl2.State = msoButtonDown
>
date: Thu, 9 Feb 2006 11:49:27 -0800
author: sjane
Re: Toggle Toolbar Button for Toggle Macro
Hi Sjane,
You get the error message because the contol with Id:=2 is "ToolsSpelling".
The built-in commands are handled by the application. You can't set their
state.
Custom controls all have the Id:=1.
Two comments regarding the code:
-- Instead of
myBar.Controls.Add Type:=msoControlButton, ID:=1
Set myControl1 = CommandBars("Custom").Controls(1)
it might be better (less error-prone) to use
Set myControl1 = _
myBar.Controls.Add(Type:=msoControlButton, ID:=1)
That way, you're sure myControl1 refers to what you think.
-- The .Temporary property of the CommandBar object is something from Excel
and has no meaning in Word, IIRC.
Regards,
Klaus
"sjane" schrieb:
>
>
> "Klaus Linke" wrote:
>
>> "sjane" wrote:
>> > In Word I have several toggle macros that I run from toolbar buttons.
>> > I would like them to behave like the Word Bold, Underline, etc.,
>> > toolbar
>> > buttons - change depending on whether the button is depressed or not.
>> > Can anyone help me with VBA code to do that? Thanks in advance.
>> >
>> > Sjane
>>
>>
>> Hi Sjane,
>>
>> Look at the help for the State property of the CommandBarButton object.
>>
>> Regards,
>> Klaus
>>
>> Klaus - thank you for your response. I spent some time reading up on the
>> "state" property and tried to test out the example code given in the VBA
>> help but didn't get very far - got an error in code below at second line
>> "Expected:=" - do you have any other suggestions I can look into? Thanks
>> in advance.
>
> Set myBar = CommandBars _
> .Add(Name:="Custom", Position:=msoBarTop, _
> Temporary:=True)
> With myBar
> .Controls.Add Type:=msoControlButton, ID:=1
> .Controls.Add Type:=msoControlButton, ID:=2
> .Visible = True
> End With
> Set myControl1 = CommandBars("Custom").Controls(1)
> myControl1.State = msoButtonUp
> Set myControl2 = CommandBars("Custom").Controls(2)
> myControl2.State = msoButtonDown
>
>>
date: Mon, 13 Feb 2006 17:39:14 +0100
author: Klaus Linke
|
|