Populate list box with file folders

0 Agios

Well-known Member
Joined
Feb 22, 2004
Messages
570
Office Version
  1. 365
I have this code thats made to populate a list box with Excel files, what i need is to populate the list box with regular yellow file folders. What do i need to change "*.xls" to ?




Dim I As Long

With Application.FileSearch
.NewSearch
.LookIn = "\\BRYANTSERVER\Documents\Estimating\RCO Tracker folders"
.FileType = msoFileTypeAllFiles
.filename = "*.xls"
.Execute
For I = 1 To .FoundFiles.Count
ListBox2.AddItem .FoundFiles(I)
Next I
End With
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I have this code thats made to populate a list box with Excel files, what i need is to populate the list box with regular yellow file folders. What do i need to change "*.xls" to ?




Dim I As Long

With Application.FileSearch
.NewSearch
.LookIn = "\\BRYANTSERVER\Documents\Estimating\RCO Tracker folders"
.FileType = msoFileTypeAllFiles
.filename = "*.xls"
.Execute
For I = 1 To .FoundFiles.Count
ListBox2.AddItem .FoundFiles(I)
Next I
End With

The only yellow file folders that I am familiar with are the ones sold at a statinery store. If you mean just any file, then you can substitute the xls with and asterisk wildcard (.filename = "*.*")
 
Upvote 0
this is what i am using and it don't work "Object does not support this property method " error. Any ideas?

Dim I As Long

With Application.FileSearch
.NewSearch
.LookIn = "\\BRYANTSERVER\Documents\Estimating\RCO Tracker folders\"
.FileType = msoFileTypeAllFiles
.filename = "*.*"
.Execute
For I = 1 To .FoundFiles.Count
ListBox2.AddItem .FoundFiles(I)
Next I
End With
 
Upvote 0
Please paste code between code tags. Click the # icon on the toolbar to insert them.

You must be using 2003- Excel since FileSearch was removed in 2007. You should move away from FileSearch solutions.

/s looks in subfolders. /ad looks for folders. For more command shell Dir help, see:
Dir - list files and folders | Windows CMD | SS64.com
Code:
Sub Main()
  Dim myDir As String
  myDir = "\\BRYANTSERVER\Documents\Estimating\RCO Tracker folders\"
  ListBox2.List = Split(CreateObject("Wscript.Shell").Exec("cmd /c dir " & _
      """" & myDir & """" & " /b /s /ad").StdOut.ReadAll, vbCrLf)
End Sub
 
Upvote 0
Please paste code between code tags. Click the # icon on the toolbar to insert them.

You must be using 2003- Excel since FileSearch was removed in 2007. You should move away from FileSearch solutions.

/s looks in subfolders. /ad looks for folders. For more command shell Dir help, see:
Dir - list files and folders | Windows CMD | SS64.com
Code:
Sub Main()
  Dim myDir As String
  myDir = "\\BRYANTSERVER\Documents\Estimating\RCO Tracker folders\"
  ListBox2.List = Split(CreateObject("Wscript.Shell").Exec("cmd /c dir " & _
      """" & myDir & """" & " /b /s /ad").StdOut.ReadAll, vbCrLf)
End Sub

Works great, thank you
 
Upvote 0

Forum statistics

Threads
1,221,706
Messages
6,161,406
Members
451,702
Latest member
Kc3475

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