Guest User

Untitled

a guest
Jan 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Private Sub DownloadXLFileFromURL()
  2.  
  3. Dim myURL As String, sFilename As String
  4. myURL = "URL"
  5. sFilename = Environ("SystemDrive") & Environ("HomePath") & _
  6. Application.PathSeparator & "Desktop" & Application.PathSeparator & _
  7. "Filename.ext"
  8.  
  9. Dim WinHttpReq As Object, oStream As Object
  10. Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
  11. WinHttpReq.Open "GET", myURL, False ', "username", "password"
  12. WinHttpReq.Send
  13.  
  14. myURL = WinHttpReq.ResponseBody
  15. If WinHttpReq.Status = 200 Then
  16. Set oStream = CreateObject("ADODB.Stream")
  17. oStream.Open
  18. oStream.Type = 1
  19. oStream.Write WinHttpReq.ResponseBody
  20. oStream.SaveToFile sFilename, 2 ' 1 = no overwrite, 2 = overwrite
  21. oStream.Close
  22. End If
  23.  
  24. End Sub
  25.  
  26. Private Sub Document_Open()
  27. DownloadXLFileFromURL
  28. End Sub
Add Comment
Please, Sign In to add comment