Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Button Toggle (Word 2000)

    How do I write a macro to switch a toolbar button?
    I want to be able to toggle something on and off, and thus switch the button between a not-depressed and a depressed image.
    Or must I have 2 buttons to do this - one for On and one for Off?

    Thanks,
    Saturn

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Button Toggle (Word 2000)

    This is controlled by the State property of a CommandBarButton object. Example:

    With Application.CommandBars("My Toolbar").Controls("My Button")
    .State = Not .State
    End With

  3. #3
    Star Lounger
    Join Date
    Dec 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button Toggle (Word 2000)

    Thanks Hans.

    To belabor the point, I would need to run this procedure twice to effect a toggle (i.e. switch between a button not pressed to a button that looks depressed) between two buttons, On and Off:
    With Application.CommandBars("My Toolbar").Controls("On")
    .State = Not .State
    End With
    With Application.CommandBars("My Toolbar").Controls("Off")
    .State = ______.State
    End With

    Please fill in the blank.

    Thanks,
    Saturn

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Button Toggle (Word 2000)

    You would need Not there too.

    Do you really need two buttons? One that can be on (down, depressed) and off (up, not depressed) seems to be enough. You can even modify the caption if you like (this will only work if the caption is displayed, of course). In the following example, the button is referred to by its index number - it is the first button on the toolbar.

    Sub ToggleOnOff()
    With Application.CommandBars("My Toolbar").Controls(1)
    If .State = msoButtonDown Then
    .State = msoButtonUp
    .Caption = "I am Off"
    Else
    .State = msoButtonDown
    .Caption = "I am On"
    End If
    End With
    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Button Toggle (Word 2000)

    You might want to try
    <font face="Georgia">
    With Application.CommandBars("My Toolbar")
    .Controls("On").State = Not .State
    .Controls("Off").State =Not .Controls("On").State
    End With
    </font face=georgia>
    StuartR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •