[VBA] Select files and get path in the cell

zeromax1

Board Regular
Joined
Mar 20, 2020
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hi all. I am currently looking for a VBA which can get the full path of the selected file in the specific column.

I found a VBA code which can help to get all the files from a selected folder. However, I want to breakdown into the selected files.

VBA Code:
Option Explicit
Sub listAllFiles()
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("D:\Testing\20200626")
Call GetFileDetails(objFolder)
End Sub
Function GetFileDetails(objFolder As Scripting.Folder)
Dim objFile As Scripting.file
Dim nextRow As Long
Dim objSubFolder As Scripting.Folder
nextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
For Each objFile In objFolder.Files
If objFile Like "*.xlsx*" Then  '(can delete if u want to list all type of files)
    Cells(nextRow, 1) = objFile.Name
    Cells(nextRow, 2) = objFile.Path
    Cells(nextRow, 3) = objFile.Size
    Cells(nextRow, 4) = objFile.Type
    Cells(nextRow, 5) = objFile.DateCreated
    Cells(nextRow, 6) = objFile.DateLastModified
    nextRow = nextRow + 1
   
End If  '(can delete if u want to list all type of files)
Next
For Each objSubFolder In objFolder.SubFolders
    Call GetFileDetails(objSubFolder)
Next
End Function

Many thanks for all experts
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Cross posted Get the file path of the selected files

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Thank you for your remind.

I do also have a new thread for the subject questions in another forum.

Another thread

It still cannot get the solution right now.

Cross posted Get the file path of the selected files

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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