+ Reply to Thread
Results 1 to 13 of 13

Populate a Combo Box with the filename from a Folder in VBA?

  1. #1
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Unhappy Populate a Combo Box with the filename from a Folder in VBA?

    Morning,

    I am struggling with this one...

    I am trying to populate a combo box with the filename from a given folder, ideally without showing their .xls extension if possible.

    Please Login or Register  to view this content.
    Any idea on how to do that will be more than welcome!

    Thanks
    Ludo
    Last edited by Coume; 08-17-2009 at 07:06 AM. Reason: Forgot to mention in VBA...

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    Where is the combobox? If it's on a worksheet what type is it?

    This code will load the names of all files in a selected folder
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    Hello there,

    It is indeed on the worksheet and it is a Combo Box (not a List Box)

    I will give a go to your code!

    Thanks a lot
    Ludo

  4. #4
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    Ok, I get a compile error on the following:
    Me.ComboBox1.AddItem Left(filTemp.Name, Len(filTemp.Name) - 4)

    I double checked and my combo on worksheet1 called "Master" is indeed called ComboBox1 so I am not sure what it was there. :/

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    It depends on the type of combbox, from which menu did you add it. Maybe attach the workbook

  6. #6
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    I added it by clicking on the ComboBox button from the Control Toolbox toolbar (View > Toolbars > control Toolbox)

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    The code needs changing to use on a worksheet
    Please Login or Register  to view this content.
    You can run the code from a button or a suitable event, maybe the wokshhet_activate, or workbook_open

  8. #8
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Unhappy Re: Populate a Combo Box with the filename from a Folder in VBA?

    Ok, I really don't get this one

    It still does not work and I can't see what I am doing wrong...
    I attached the entire .xls as it may be easier for you to spot the obvious mistake that I must be making...

    Thanks

    Ludo puzzled
    Last edited by Coume; 08-17-2009 at 06:56 AM.

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    No idea what or how you did it but the combobox is a picture.

    delete the picture and try adding a new combobox
    Cheers
    Andy
    www.andypope.info

  10. #10
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    Stupid me!

    When I was messing around before, I removed the function from the combo =EMBED("Forms.ComboBox.1","") and I forgot to put it back in... Hence why it was showing up as an image.

    Thanks for pointing this out as I was become crazy!


    Ludo

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    I've amended the code to work with a fixed path an put he code in the correct places

    You need to stop you Before_Save code in order to make changes to the VBA
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    Thanks Roy.

    May I ask why the code should go in the module section?

    I taught myself the macro coding in Excel based on my knowledge from other languages but I don't really know the good practice in terms of where to place the code etc.

    Basically, which VBA should you save in the workbook, sheet or module :?

    Thanks for everything!
    Ludo

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Populate a Combo Box with the filename from a Folder in VBA?

    I would usually restricy code in the worksheet or workbook event modules to the pre-set ones, any other code I place in standard modules

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1