Change this code to use MSXML2.XMLHTTP60

a0k0a7 used Ask the Experts™
The reason I would like to change the code to use the MSXML2.XMLHTTP60 is because I want to be able to pass the user credentials during the upload to the sharepoint library.

    Dim SharepointAddress As String
    Dim LocalAddress As String
    Dim objNet As Object
    Dim FS As Object

    ' Where you will enter Sharepoint location path
    SharepointAddress = "\\sharepoint path to document library"  & "\" 
      ' Where you will enter the file path, ex: Excel file
    LocalAddress = "your file path"                                     
    Set objNet = CreateObject("WScript.Network")
    Set FS = CreateObject("Scripting.FileSystemObject")
    If FS.FileExists(LocalAddress) Then
    FS.CopyFile LocalAddress, SharepointAddress
    End If
    Set objNet = Nothing
    Set FS = Nothing

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Walter CurtisSharePoint AED
Distinguished Expert 2018

Why? When you upload to a document library per default credentials are "read" and can be used. Why reinvent the wheel?


@sneekCo, the user that will execute the code, won't have access to the sharepoint library, that's why I need to pass the credentials.
Set xmlhttp = CreateObject("Microsoft.XMLHTTP") 'New MSXML2.XMLHTTP.60
    xmlhttp.Open "PUT", sharepointFileName, False, UserName, pw
    xmlhttp.Send sBody


I searched for information on this topic, all the posts on excel vba forums, stack overflow and msdn point to this method. I am still unable to get it working with SharePoint online, I may need utility code to use the Upload.aspx instead of direct authentication to the SharePoint document library.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial