I am using this code to loop through the files in sharepoint using excel VBA. This code is working fine when I am using the local drive path. But when I replace the path with my sharepoint path, I am getting an error saying ‘Path Not Found’ at fs.GetFolder
Please kindly advice
Code I am using is:
Private Sub CommandButton2_Click() Dim folder As Variant Dim f As File Dim fs As New FileSystemObject Dim fs1 As New OLEObject Dim RowCtr As Integer Dim FPath As String Dim wb As Workbook FPath = "my URL" Set fs = CreateObject("Scripting.FileSystemObject") RowCtr = 1 Set folder = fs.GetFolder(FPath) '<=Variable Location For Each f In folder.Files Cells(RowCtr, 1).Value = f.Name RowCtr = RowCtr + 1 Next f End Sub
You’ll need to map sharepoint to a Windows drive letter, as outlined in SharePoint StackExchange. Once it’s mapped you’ll be able to open as a local drive path.