• Get value from comboBox control (VBA/Word2003)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Get value from comboBox control (VBA/Word2003)

    Author
    Topic
    #440534

    Without testing, I think you need
    strSelection = CommandBars.ActionControl.Text

    cheers Klaus

    Viewing 1 reply thread
    Author
    Replies
    • #1055649

      Thanks Klaus, but I did try that, or rather;

      strSelection = CommandBars.ActionControl.TAG

      .Text is not valid property in this case. .Tag returns “”
      That said, I haven’t set any ‘tags’ in the comboBox nor do I know whether I need to.

      Other suggestions?

      Cheers

      • #1055655

        Although .Text isn’t listed as a property of ActionControl by IntelliSense, you can still use it. ActionControl can be any kind of commandbarcontrol, so IntelliSense doesn’t know whether .Text is appropriate. But since your control is a combo box, it is valid.

        Another way to get the text would be

        strSelection = CommandBars(“Font”).Controls(1).Text

        • #1055670

          Thank you very much Hans and Klaus. You’re both absolutely right!

          I thought I had actually tried that before too, but obviously I had something different because it didn’t work previously.

          Thanks again, Greig.

    • #1055647

      Hi,

      I’ve searched, read, pulled hair and am now totally stumped!

      I am creating a conversion application that uses a limited font set. I’ve created a comboBox control and populated it with the allowable fonts. The problem is that I don’t know how to get the value from the user’s selection in the font list. Here’s a sample of what I’ve got. I hope someone can help me. I’m sure it is easy and I’ve just totally overlooked something.

      Sub BuildFontList()
      Dim barFont
      Set barFont = CommandBars _
      .Add(Name:=”Font”, Position:=msoBarTop, _
      Temporary:=False)
      barFont.Visible = True

      Set ctrlFonts = barFont.Controls _
      .Add(Type:=msoControlComboBox)

      With ctrlFonts
      .AddItem “Arial”
      .AddItem “Arial Black”
      .AddItem “Book Antiqua”
      .AddItem “Century Gothic”
      .AddItem “Comic Sans MS”
      .AddItem “Verdana”
      .Style = msoComboLabel ‘msoComboNormal
      .OnAction = “FontSelection” ‘”ScrollToQuarter”
      End With
      End Sub

      Sub FontSelection()
      ” ?? herehere??
      strSelection = ?? This is my test and where I am totally stuck.

      Once I can get the selected font, I’d use the following.
      Selection.Font = ActiveDocument.Fonts(??)

      End Sub

      If someone can fill in the gaps, that would be great.

      Cheers
      Greig.

    Viewing 1 reply thread
    Reply To: Get value from comboBox control (VBA/Word2003)

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

    Your information: