问题
I have written a macro (with the help of several internet sources) that will iterate through files in a SharePoint folder online and extract the needed info out of said folder, then move onto the next.
However, it does not seem to locate the folder path and produces an error telling me it cannot locate folder path. I have checked the path by copying and pasting the folder into google chrome and it works.
I'm sure this will be a silly and stupid fix but i cannot seem to get it to work.
Sub ExtractComments()
Dim mswb, slwb As Workbook
Dim mscommentsws, mssheetsenteredws, slcommentsws, slcoverpagews As Worksheet
Dim mscommentswslrow, mssheetsenteredwslrow, slcommentswslrow As Long
Dim folderURL As String
Dim fso As FileSystemObject
Dim folder As folder
Dim file As file
folderURL = InputBox("Please enter Sharepoint link of the Internal VV folder")
If folderURL = vbnullstirng Then Exit Sub
Set fso = New FileSystemObject
If Not fso.FolderExists(folderURL) Then
MsgBox ("Folder does not exist")
Exit Sub
Else
Set folder = fso.GetFolder(folderURL)
End If
Set mswb = ThisWorkbook
Set mscommentsws = mswb.Sheets("AllComments")
Set mssheetsenteredws = mswb.Sheets("SheetsEntered")
mscommentswslrow = mscommentsws.Range("D" & Rows.count).End(xlUp).Row
mssheetsenteredwslrow = mssheetsenteredws.Range("A" & Rows.count).End(xlUp).Row
For Each file In folder.Files
Set slwb = Workbooks.Open(folderURL & file.Name)
Set slcommentsws = slwb.Sheets("Comments")
Set slcoverpagews = slwb.Sheets("Cover Page")
Dim fileURLrange, URLname As Variant
Dim count As Long
slcommentswslrow = slcommentsws.Range("E" & Rows.count).End(xlUp).Row
fileURLrange = mssheetsenteredws.Range("A1:A" & mssheetsenteredwslrow)
URLname = f.Name
回答1:
Try using the following structure for your URL:
\\sharepoint.yourfirmname.com@SSL\DavWWWRoot\sites\site-name\library-name\
This would translate from the webpage URL of:
https://sharepoint.yourfirmname.com/sites/site-name/library-name/Forms/AllItems.aspx
leave the @SSL\DavWWWRoot part as it is, no need to change.
Also, ensure that you can connect to the server using Windows explorer.
Paste the path into Windows explorer. If you get an error it may be that the path is invalid, or possibly that the connection has timed out. A quick way to check/fix both is to
- Open Internet Explorer
- Browse your sharepoint to the library in question
- Then,
- If using 'classic experience' view, go to the Ribbon>Library>Open with explorer
- if not using 'classic' view, go to view selector menu roughly under the Share button and click View in File Explorer
This will force a new connection to the server and you can now copy/paste the full path from the Windows Explorer address bar.
The path should then work just like other windows filesystem paths. Especially if you use the @SSL\DavWWWRoot method above. In my experience though, it will need 'reconnecting' from time to time. Usually every few days or after a reboot.
来源:https://stackoverflow.com/questions/60038013/vba-macro-cannot-find-folder-path