Insert filename

Hatye

Board Regular
Joined
Jan 11, 2010
Messages
143
Hi,

I want to browse my computer (perhaps using .GetOpenFileName?) to find one or multiple files. I don't want to insert the whole file, just the file name with extension (e.g. ".jpg")! Is that possible?

If so, I want the file names to be separeted using comma. The files may be in different folders, so I may need to run the macro several times to insert a new file name.

It would also be nice if there is a way to easily delete the filename, without going into the cell and delete it manually.


The file names should be inserted into cell W13.



Thanks for any help :)
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
To prompt the user to select one or more JPG files:-
Code:
Dim vFilename As Variant
vFilename = Application.GetOpenFilename(FileFilter:="Image files (*.jpg), *.jpg", MultiSelect:=True)
If Not IsArray(vFilename) Then Exit Sub [COLOR=green]' if users clicks 'Cancel'[/COLOR]

This will put the names in an array called vFilename which you can use in whatever way you want. To copy the names to cell W13:-
Code:
Dim iPtr As Long
For iPtr = LBound(vFilename) To UBound(vFilename)
  If IsEmpty(Range("W13")) Then
    Range("W13") = vFilename(iPtr)
  Else
    Range("W13") = Range("W13") & "," & vFilename(iPtr)
  End If
Next iPtr
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

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