List absolute path + file extensions in directory

S42k20

New Member
Joined
Jul 12, 2020
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hello everyone,

I found a nice piece of VBA, to list files in a directory including
- the file name
- file / folder
- relative file path

My question would be, if anyone could tell me how to change this code so that I will have two additional columns for:
- file extension
- absolute file path

The code from Link is the following I am using:

VBA Code:
Sub DownloadListFromSharepoint()

    Dim SharepointAddress As String
    Dim LocalAddress As String
    Dim objFolder As Object
    Dim objNet As Object
    Dim objFile As Object
    Dim FS As Object
    Dim rng As Range
    SharepointAddress = "https://abc.onmicrosoft.com/TargetFolder/"

    Set objNet = CreateObject("WScript.Network")
    Set FS = CreateObject("Scripting.FileSystemObject")
    objNet.MapNetworkDrive "A:", SharepointAddress
    
    Set objFolder = FS.getfolder("A:")
    
    Set rng = ThisWorkbook.Worksheets(1).Range("a1")
    rng.Value = "File Name"
    rng.Offset(0, 1).Value = "Folder/File"
    rng.Offset(0, 2).Value = "Path"
    GetAllFilesFolders rng, objFolder, "" & strSharepointAddress
    objNet.RemoveNetworkDrive "A:"
    Set objNet = Nothing
    Set FS = Nothing

End Sub

Public Sub GetAllFilesFolders(rng As Range, ObjSubFolder As Object, strSharepointAddress As String)
    Dim objFolder As Object
    Dim objFile As Object
    
    For Each objFile In ObjSubFolder.Files
        rng.Offset(1, 0) = objFile.Name
        rng.Offset(1, 1) = "File"
        rng.Offset(1, 2) = Replace(objFile.Path, "A:\", SharepointAddress)
        Set rng = rng.Offset(1, 0)
    Next
    For Each objFolder In ObjSubFolder.subfolders
        rng.Offset(1, 0) = objFolder.Name
        rng.Offset(1, 1) = "Folder"
        rng.Offset(1, 2) = Replace(objFolder.Path, "A:\", SharepointAddress)
        Set rng = rng.Offset(1, 0)
        GetAllFilesFolders rng, objFolder, strSharepointAddress
    Next
End Sub

Thanks for any help and best regards!
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

S42k20

New Member
Joined
Jul 12, 2020
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hi, does anybody have an idea here! I would really appreciate it very much.
Thank you :)
 

Watch MrExcel Video

Forum statistics

Threads
1,119,295
Messages
5,577,237
Members
412,777
Latest member
MrGray
Top