VBA - File Dialog Show Result in Textbox on userform

drluke

Active Member
Joined
Apr 17, 2014
Messages
314
Office Version
  1. 365
Platform
  1. Windows
I cannot find how to change this code so that the file path of the selected files are place in an existing text box (TextBox3) in my userform.

Here is the code I'm using

Code:
Private Sub CommandButton1_Click()
Dim fDialog As FileDialog, i As Integer
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
fDialog.AllowMultiSelect = True
fDialog.Title = "Select Files"
fDialog.InitialFileName = "T:\Finance\SohoMaccs\2018Maccs\Monthly Reports\"
fDialog.Filters.Add "Excel files", "*.xlsx"
If fDialog.Show = -1 Then
    For Each it In fDialog.SelectedItems
    Debug.Print it
    Next it
End If

End Sub

The above code works until files are selected. Thereafter nothing happens.
 
Why have you removed the code from the button_click & out it into a normal module?
If you put it back into the click event as shown by DanteAmor then it should work.

Also, for future reference, if you post code to the site & then change it without our knowledge, you really need to let us know.
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The last:

UserForm1.TextBox3.Value = Left(fDialog.SelectedItems(1), n)
 
Upvote 0

Forum statistics

Threads
1,215,018
Messages
6,122,703
Members
449,093
Latest member
Mnur

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