I "borrowed" this from a post online which appears to address the issue i have opening files from our internal https site:
It executes perfectly however the downloaded Word document is corrupt and cannot be used.Code:Private Sub CommandButton21_Click() Dim FileNum As Long Dim FileData() As Byte Dim WHTTP As Object mainUrl = "https://mycompany.com/" fileUrl = "https://mycompany.com/sdd_template.docx" filePath = "C:\Users\me\Desktop\sdd_template.docx" myuser = "[email protected]" mypass = "******" strAuthenticate = "start-url=%2F&user=" & myuser & "&password=" & mypass & "&switch=Log+In" Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1") WHTTP.Open "POST", mainUrl, False 'WHTTP.Open "POST", fileUrl, False WHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" WHTTP.Send strAuthenticate 'Then you have to GET direct file url WHTTP.Open "GET", fileUrl, False WHTTP.Send FileData = WHTTP.ResponseBody Set WHTTP = Nothing 'Save the file FileNum = FreeFile Open filePath For Binary Access Write As #FileNum Put #FileNum, 1, FileData Close #FileNum MsgBox "File has been saved!", vbInformation, "Success" End Sub
Anybody tried similar and succeeded?
Thanks
Steve




Reply With Quote
