The following code purpose is to upload files to a sharepoint library, I run it from Excel using a form control, prior to it I run using an ActiveX button.
UserName = "myusername@sharepoint.com" pw = "mypassword" SharePointURL = "\\xyz.sharepoint.com@SSL\DavWWWRoot\sites\uat\a1docsuat" & "\" Set LobjXML = CreateObject("Microsoft.XMLHTTP") Set fso = CreateObject("Scripting.FileSystemObject") Set fldr = fso.GetFolder("c:/vba2sharepoint/") For Each f In fldr.Files sharepointFileName = SharePointURL & f.Name 'If sharepointFileName Like "*.txt" Then Set tsIn = f.OpenAsTextStream sBody = tsIn.ReadAll tsIn.Close Set xmlhttp = CreateObject("MSXML2.XMLHTTP.4.0") xmlhttp.Open "PUT", sharepointFileName, False, UserName, pw xmlhttp.Send sBody 'End If Next f
@jkpieterse After changing the sharepointURL variable, I don't get any error but the files are not upload it, any ideas?
Public Sub CopyToSharePoint()UserName = "myusername@sharepoint.com" pw = "mypassword" sharepointUrl = "https://xyz.sharepoint.com/sites/uat/_layouts/15/start.aspx#/a1docsuat/" Set LobjXML = CreateObject("Microsoft.XMLHTTP") Set fso = CreateObject("Scripting.FileSystemObject") Set fldr = fso.GetFolder("c:\vba2sharepoint\") For Each f In fldr.Files sharepointFileName = sharepointUrl & f.Name 'If sharepointFileName Like "*.txt" Then Set tsIn = f.OpenAsTextStream sBody = tsIn.ReadAll tsIn.Close 'Set xmlhttp = CreateObject("MSXML2.XMLHTTP.4.0") Set xmlhttp = New MSXML2.XMLHTTP60 xmlhttp.Open "PUT", sharepointFileName, False, UserName, pw xmlhttp.Send sBody 'End If Next fEnd Sub
I'm sorry, I am unable to help with the Sharept I'm afraid!
a0k0a7
ASKER
@jkpieterse thanks for trying, I feel like I am close to get it working, I will give you assistance points just to help me figure out the issue that I didn't have the XML library installed on my system.
and still have the same error message.