Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipsis Textbox for VBA Userform File Select

I am trying to create a path selection user interface for an extensive VBA program I've been working on, but I can't seem to get the ellipsis textbox that I'd like. This is a very common feature, especially in option tables. This is an example of what I'd like to get, straight from the VBA Options panel:

ellipsis_textbox_example

I would LOVE to find a way to get the same functionality in a Userform. The only solution that I've found thus far is to use a combo box with the ellipsis arrow option enabled. However, there doesn't seem to be an apparent way to use the activation of the combo box arrow to run a dialog box, nor does there seem to be a way to make it look UNLIKE a combo box. Last resort I use a button below the text box, but I'd really prefer a less-bulky way of doing this.

Any solution would be greatly appreciated.

like image 570
jaysoncopes Avatar asked Oct 18 '22 21:10

jaysoncopes


1 Answers

The only solution that I've found thus far is to use a combo box with the ellipsis arrow option enabled. However, there doesn't seem to be an apparent way to use the activation of the combo box arrow to run a dialog box, nor does there seem to be a way to make it look UNLIKE a combo box

Your suggestion does work, and it is surely less complex and more elegant than having two controls work together, Button + Textbox.

A Combo can achieve perfectly the desired feature, in the following way.

1) In design mode, set the button style to Ellipsis

         DropButtonStyle = fmDropButtonStyleEllipsis

And eventually, make the ellipsis show up only when the combo is entered, by setting the design-time property:

         ShowDropButtonWhen = ShowDropButtonWhenFocus

2) If needed, you can set other design-time properties to have some look and feel. The defaults look pretty good however.

3) Add the following handler to the parent userform. The snippet simulates the launching of a dialog and getting a new value or cancelling. It does not show any dropdown window. (but you still have control over that: if you want to show it according to some condition, you still can call the method ComboBox1.DropDown)

Private Sub ComboBox1_DropButtonClick()
    ' The following two lines avoid to call the routine twice, at entry and at exit
    Static i As Integer
    i = (i + 1) Mod 2: If i = 0 Then Exit Sub

    With ComboBox1
        s = InputBox("enter some text", , .Value) '<~~ simulates any dialog
        If s <> "" Then .Value = s
        SendKeys ("{Enter}") '<~~ to close immediately the dropdown window
    End With
End Sub

Try it ;)

like image 50
A.S.H Avatar answered Oct 30 '22 23:10

A.S.H