Code Works - but only sometimes? - get list of files in sharepoint folder

Xipha

New Member
Joined
Oct 29, 2013
Messages
16
Hi I am running the following code, which was working great on my computer, and I tested it on a couple other computers no problem. But some computers started to have an error on the line Sheet1.Activate (not sure what the error is that my coworker got just that they needed to debug).

When I went to go test it, my debugger highlighted the line Set xfolder = xfs.GetFolder("//companydomain.sharepoint.com/projects/z Aerials/Photos") Run Time Error '76:Path not found (it said it could not find the path - but it was working a couple weeks ago and I don't think anything has changed). I'm not sure why I get a different error than my coworkers. We all use Sharepoint and have it logged in through file explorer. Suggestions to fix this code, or on code that will work better?

Thanks

Code:
Sub CreateList()
    Dim xfolder As Folder
    Dim xf As File
    Dim xfs As New FileSystemObject
    Dim xRowCtr As Integer
    
    Sheet1.Activate
    xRowCtr = 2
    Set xfolder = xfs.GetFolder("//companydomain.sharepoint.com/projects/z  Aerials/Photos")
    For Each xf In xfolder.Files
       Cells(xRowCtr, 1).Value = xf.Path + xf.Name
       xRowCtr = xRowCtr + 1
    Next xf
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
HTH. Dave
Code:
Sub Testt()
Dim xfolder As Object, xf As Object, xfs As Object, xRowCtr As Integer
Set xfs = CreateObject("scripting.filesystemobject")
xRowCtr = 2
Set xfolder = xfs.GetFolder("//companydomain.sharepoint.com/projects/z  Aerials/Photos")
For Each xf In xfolder.Files
Sheets("sheets1").Cells(xRowCtr, 1).Value = xf.Path & "/" & xf.Name
xRowCtr = xRowCtr + 1
Next xf
Set xfolder = Nothing
Set xfs = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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