listbox populate

Lauren279

Board Regular
Joined
Aug 19, 2014
Messages
95
hi

I have a the following

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer

'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("C:\file loction\find")
i = 5
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'print file name
Cells(i + 1, 3) = objFile.Name

i = i + 1
Next objFile
MsgBox "Done!"

which I believe I got from here, it is fantastic and does what I need, only thing I want to change is I would like it to have the information be populated in a Userform listbox rather than cells on a worksheet.

is there a easy way to change this??

the information is only visual, so I don't need to store the list information in the workbook and I would prefer the information to not go on to a particular worksheet, if I can help it

thanks for any help you can provided
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Re: listbox populate HELP

Try

Code:
ListBox1.Clear

For Each objFile In objFolder.Files[COLOR=#333333]'print file name[/COLOR]
[COLOR=#333333]       Listbox1.AddItem [/COLOR][COLOR=#333333] = objFile.Name[/COLOR]
[COLOR=#333333]Next objFile
[/COLOR]
 
Last edited:
Upvote 0
Re: listbox populate HELP

Remove the = after AddItem.
Code:
Listbox1.AddItem objFile.Name
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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