excel vba to upload file to sharepoint

别等时光非礼了梦想. 提交于 2020-01-23 12:04:40

问题


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!


回答1:


(I can't add comments to Olly's answer since I'm new, so I'll put my comments in this new answer.)

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



回答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


来源:https://stackoverflow.com/questions/50510770/excel-vba-to-upload-file-to-sharepoint

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