Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

show files in combobox based on selected folder in another combobox

0

hi

currently  I  work on  project  . I  have  to  comboboxes  the  combobox 1   contains lis  of  folders  based on directory C:\path  and  each  folder  contains  many  files .so   I  would  when  select  the  folder from  combobx1   then  populate  the  files in combobox2 are  relating  selected folder from  combobox1. currently  it  brings  all  of  the  files  are  existed  in  directory  . it  should  just  bring  the  files  based on selected folder from combobox1.

Answer
Discuss

Answers

0
Selected Answer

Kalil

When ComboBox 1 changes, it triggers your macro starting:

Private Sub ComboBox1_Change()

    Dim fs, f, f1, fc, s
    Dim folderspec

    folderspec = "D:\All"
but you need to add the chosen folder to folderspec, using the addition in bold below:
Private Sub ComboBox1_Change()

    Dim fs, f, f1, fc, s
    Dim folderspec

    folderspec = "D:\All" & "\" & ComboBox1.Value

so FSO will then use the files in that folder to populate ComboBox2 (using the rest of your code). Click the down arrow in ComboBox2 and you will see the files.

Hope this helps.

Discuss

Discussion

much appreciate for  your help !
Kalil (rep: 36) Nov 17, '21 at 2:28 am
Thanks for selecting my answer Kalil. Have you tried ComboBox2. SetFocus after its list has been created?
John_Ru (rep: 6142) Nov 17, '21 at 3:19 am
Have you tried ComboBox2. SetFocus after its list has been created?
no , but   I will do  it
Kalil (rep: 36) Nov 17, '21 at 3:41 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login