Consulting

Results 1 to 2 of 2

Thread: how to speed up processing string values from folder name and load into listbox

  1. #1

    Reading folder names and populating listbox

    Does anyone know of a good way to read file system folders and populate a listbox with these names? I am currently using the following lines of code to do this and it works. However, it is very sluggish and was wandering what a better way to do this would be. Here is the code I am using:

    Dim fs, f, f1, fc, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(\\ohlew0010\plis\map83)
        Set fc = f.Subfolders
        For Each f1 In fc
            'following line adds folder names to cmbStates listbox
            cmbStates.AddItem (f1.Name)
       Next
    Any help is greatly appreciated!!

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    File Scripting Object is what I use. You can try using Early Binding instead of Late Binding. Set a reference to the Microsoft Scripting Runtime (Tools | References).

    Then instead of using CreateObject just use New.
     Set fs = New FileSystemObject

Posting Permissions

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