Refreshing a ComboBox Issues

rjn2002

New Member
Joined
Feb 23, 2009
Messages
8
Hi all,

I am trying to populate an ActiveX ComboBox on an Excel spreadsheet with file names from a given directory. Currently I have a "refresh" button that users can click to refresh the drop-downs when they add new files to the folder. I would like to automatically do this.

I have tried just about all of the even properties with no success.

In using GotFocus(), when the list refreshes, the drop-down does not fully expand. It's only after clicking the list again that you see the drop-down box fully expanded.

The dropButt*******() creates problems because it fires when the drop-down appears and disappears. Thus after the user selects an item, the list is cleared, thus the user can never actually select an item.

I have thought about checking the mouse position in the dropbutt******* event, and if it is not where the dropdown arrow is, then don't refresh the lists, but this is very risky, especially if I don't get the coordinates exactly correct.

I feel like I am closest with the GotFocus approach if I can just get the drop-down to fully expand after it triggers. Perhaps someway to trigger selecting it again to force it to fill the drop-down fully?

"cmbsWPM" is the name of the combobox I am working with.


Code:
Private Sub cmbsWPM_gotfocus()
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False

    cmbsWPM.Clear

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set dealdir = fso.getFolder("C:\SFW\moodys Macros\econ_files")
    Set deals = dealdir.Files
    
    For Each deal_file In deals
        If fso.GetExtensionName(UCase(deal_file.Path)) = "WPM" Then
        'Change path To suit
            cmbsWPM.AddItem (deal_file.Name)
        End If
    Next
    
    On Error GoTo 0
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I was able to get this to work by adding the following code, though I am afraid if I add more to the other methods, this could be dangerous:

Code:
Private Sub cmbsWPM_DropButt*******()
    DoEvents
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top