VBA Macro cannot find folder path

二次信任 提交于 2021-01-29 12:12:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!