Inputting single file information instead of batch folders

Fusion187

New Member
Joined
Sep 1, 2017
Messages
2
Hello everybody (hello doctor nick)

I'm a long time reader and follower first time posting.

From this amazing community i was able to import multipul file names into excel. One down side was that sometimes i only need to select one file instead of the whole folder. I used the following code but it does not work.

Sub GetFile()

Dim xFso As Object
Dim xFolder As Object
Dim xFile As Object
Dim xFiDialog As FileDialog
Dim xPath As String
Dim i As Integer

Set xFiDialog = Application.FileDialog(msoFileDialogFilePicker)

If xFiDialog.Show = -1 Then
xPath = xFiDialog.SelectedItems(1)
End If

Set xFiDialog = Nothing

If xPath = "" Then Exit Sub

Set xFso = CreateObject("Scripting.FileSystemObject")

Set xFolder = xFso.GetFile(xPath)

i = 1

For Each xFile In xFolder.Files


i = i + 1

ActiveSheet.Cells(i, 1) = Left(xFile.Name, InStrRev(xFile.Name, ".") - 1)

ActiveSheet.Cells(i, 8) = xPath

Next

MsgBox "Completed!"

End Sub

I'm really not a programmer but i love how VB works. I've been messing around with it at work to make our lives easier. I tried to do this program but failed hard.

I would appreciate anyone and everyones help on this please.

So the end goal is i want to be able to select individual files in all different kinds of folders and extract there file names and place them into the currently selected empty cell.

Thank you all for reading this and await your thoughts and ideas.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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