excel vba to upload file to sharepoint

25,337

Solution 1

I noticed that the SharePoint URL starts with https. As such, you'll need to construct your UNC path as \\share.name.com@SSL\DavWWWRoot\site\library\.

A few things to check:

  • WebClient service is running
  • The SharePoint site is trusted in Internet Options

Solution 2

Try specifying the Sharepoint path as UNC, and using the CopyFolder method:

Sub AddSharePointFiles()

    Dim FSO As Object
    Dim FromPath As String
    Dim ToPath As String

    ToPath = "\\share.name.com\site\folder"
    FromPath = "C:\Users\Name\Documents\FolderName"

    Set FSO = CreateObject("scripting.filesystemobject")
    FSO.CopyFolder Source:=FromPath, Destination:=ToPath

End Sub
Share:
25,337
JBJB
Author by

JBJB

Updated on January 10, 2022

Comments

  • JBJB
    JBJB over 2 years

    I am trying to upload a folder from my C drive to a SharePoint library site. I have used the below code, which works fine when the ToPath is not a SharePoint library site but another folder from my C drive. Where am I going wrong?

    Sub AddSharePointFiles()
    
    Dim FSO As Object
    Dim FromPath As String
    Dim ToPath As String
    
    ToPath = "https://share.name.com/site/folder/_layouts/15/start.aspx#/LibraryName/Forms/AllItems.aspx"
    FromPath = "C:\Users\Name\Documents\FolderName"
    
    Set FSO = CreateObject("scripting.filesystemobject")
    
    FSO.CopyFile Source:=FromPath, Destination:=ToPath
    
    End Sub
    

    Thank you!

  • JBJB
    JBJB almost 6 years
    No luck with that - it still says it doesn't exist
  • Olly
    Olly almost 6 years
    Have you included the filename with the path, in the Destination?
  • Olly
    Olly almost 6 years
    Answer edited - realised you want to copy the folder, not just a file - so try the CopyFolder method.
  • seadoggie01
    seadoggie01 over 5 years
    This should be the selected answer. We've been hunting this down for so long. You are amazing. Thank you!!!