Linking textbox to vba code

chis

New Member
Joined
Mar 15, 2011
Messages
7
Hi Everyone,

I'm having problems with the following code and can't work out what I'm getting wrong, is anyone able to offer me so advice?

I have a very simple Userform with two text boxes on it, one for the folder path and the other for the file extension. The objective of the code is to publish a list of all file names of a particular extension into an excel sheet but at the moment it's doing nothing :eeek: I found the code on a forum and just adapted slightly but I have a feeling I'm not referencing the path name correctly?

Any ideas greatfully received, Many Thanks

Code:
Private Sub CommandButton1_Click()
Folder = TextBox1.text
Extension = TextBox2.text
 
First = True
RowCount = 1
Do
If First = True Then
FName = Dir(Folder & "\" & Extension)
First = False
Else
FName = Dir()
End If
If FName <> "" Then
Range("A" & RowCount) = FName
RowCount = RowCount + 1
End If
Loop While FName <> ""
End Sub

:)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Welcome to MrExcel.

Your code worked for me. Extension needs to be something like *.xls, or if you want only xls change the Dir line to:

FName = Dir(Folder & "\*." & Extension)
 
Upvote 0
Thanks very much for such a quick reply Andrew :):):)

It looks like I was forgetting the * because it's working now!

Many many Thanks
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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