• Toggle Button (Excel 2004 VBA)

    Author
    Topic
    #419993

    I want to create a toolbar with a toggle button (on of off) but I cannot get it to stay ‘in’. Help.

    Viewing 0 reply threads
    Author
    Replies
    • #949819

      Have you tried using
      mnuWhateverYouCalledIt.State = msoButtonUp
      and
      mnuWhateverYouCalledIt.State = msoButtonDown

      StuartR

      • #949861

        Stuart,

        The code that I am using is

        With CommandBars("CommandBar").Controls("Button")
            .FaceId = 1762
            .Caption = "New Caption"
            .OnAction = "New Action"
        End With

        There doesn’t seem to be a .state for controls.

        • #949863

          .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…

          • #949878

            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.

        • #949877

          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.

    Viewing 0 reply threads
    Reply To: Toggle Button (Excel 2004 VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: