Results 1 to 6 of 6
  1. #1
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Toggle Button (Excel 2004 VBA)

    I want to create a toolbar with a toggle button (on of off) but I cannot get it to stay 'in'. Help.
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

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

    Re: Toggle Button (Excel 2004 VBA)

    Have you tried using
    <code>mnuWhateverYouCalledIt.State = msoButtonUp</code>
    and
    <code>mnuWhateverYouCalledIt.State = msoButtonDown</code>

    StuartR

  3. #3
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle Button (Excel 2004 VBA)

    Stuart,

    The code that I am using is <pre>With CommandBars("CommandBar").Controls("Button")
    .FaceId = 1762
    .Caption = "New Caption"
    .OnAction = "New Action"
    End With</pre>


    There doesn't seem to be a .state for controls.
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Toggle Button (Excel 2004 VBA)

    .State is a property of a CommandBarButton. If the control is a button, you should be able to set its properties like so, more or less:

    dim cBtn as Commandbarbutton
    Set cBtn = CommandBars("CommandBar").Controls("Button")
    With cBtn...

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

    Re: Toggle Button (Excel 2004 VBA)

    As Jefferson indicated, State is a property of a CommandBarButton. In your code, IntelliSense cannot know that Controls("Button") is a CommandBarButton, so it doesn't list State as a property. You should still be able to type it yourself. Or use the code suggested by Jefferson.

  6. #6
    5 Star Lounger Ruff_Hi's Avatar
    Join Date
    Feb 2001
    Location
    New York, New York, USA
    Posts
    768
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle Button (Excel 2004 VBA)

    Thx Jeff - once I had got my caption correct, it worked like a dream.
    Thx Hanv for pointing out the intellisense short comings - shows what happens when we let the machine think for us.
    (Location Australia, then UK, but now USA. Heart, outlook, attitude, etc always Australian)
    Quote: "All Happiness is the release of internal pressure"

Posting Permissions

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