I have MS-Word Document templates stored in SharePoint.
I want to copy the contents of the word document(s) in SharePoint, and save to a local Word document using Excel VBA.
I have the following Sub (which is a template sub that I call within other subs).
I get an error
Object doesn't support this property or method
on the line stream.Write xml.responseBody.
I realise that "responseBody" is not the correct term for a Word document but I can't figure out what to put here.
Sub Letter_Template(url As String)
Dim xml As Object
Dim localFilePath As String
Dim WordApplication As Word.Application
Dim WordDocument As Word.Document
' This section lets Word to grab files from the provided url and place it into a temporary location.
localFilePath = Environ("TEMP") & "\LetterTemplate.docx"
Set xml = CreateObject("MSXML2.XMLHTTP")
xml.Open "GET", url, False
xml.Send
If xml.Status = 200 Then
Dim stream As Object
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1
stream.Write xml.responseBody
stream.SaveToFile localFilePath, 2
stream.Close
Else
MsgBox "Failed to download the file. Status: " & xml.Status
Exit Sub
End If
' Open the downloaded file in Word
Set WordApplication = New Word.Application
Set WordDocument = WordApplication.Documents.Open(localFilePath)
With WordDocument
.Display
End With
End Sub
I did model this off a similar sub I use to locate and copy Outlook templates in SharePoint so I may be missing parts needed for a Word document.
I set a breakpoint at the steam.Write line and took a screenshot of the Locals Window (cropped out url part at the top as it is sensitive).

Dim stream as Objectyou can doDim stream As ADODB.Streamand then you'll get IDE IntelliSense features working.Letter_Templatesub in the debugger but set a breakpoint on thestream.Writeline, then edit your post to show us what you see in the Autos/Locals windows.