Single file details into excel

Status
Not open for further replies.

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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Status
Not open for further replies.

Forum statistics

Threads
1,215,692
Messages
6,126,230
Members
449,303
Latest member
grantrob

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