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:
Thanks for any help and best regards!
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!