Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Option Explicit
  2. Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
  3. Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte
  4.  
  5. 'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
  6. Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
  7. oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website
  8. oXMLHTTP.Send 'send request
  9.  
  10. 'Wait for request to finish
  11. Do While oXMLHTTP.readyState <> 4
  12. DoEvents
  13. Loop
  14.  
  15. oResp = oXMLHTTP.responseBody 'Returns the results as a byte array
  16.  
  17. 'Create local file and save results to it
  18. vFF = FreeFile
  19. If Dir(vLocalFile) <> "" Then Kill vLocalFile
  20. Open vLocalFile For Binary As #vFF
  21. Put #vFF, , oResp
  22. Close #vFF
  23.  
  24. 'Clear memory
  25. Set oXMLHTTP = Nothing
  26. End Function
  27.  
  28. Sub TestingTheCode()
  29. 'This will save the Google logo to your hard drive, insert it into the
  30. ' active spreadsheet, then delete the local file
  31. SaveWebFile "http://www.google.com/intl/en/images/logo.gif", "C:GoogleLogo.gif"
  32. ActiveSheet.Pictures.Insert "C:GoogleLogo.gif"
  33. Kill "C:GoogleLogo.gif"
  34. End Sub
  35.  
  36. For i = 1 to lastRow
  37. cellAddress = Replace(Range("A" & i).Hyperlinks(1).Address, "mailto:", "")
  38. 'Something to get the file name from the whole file name here
  39. SaveWebFile cellAddress, destinationFolder & filename
  40. Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement