Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
- Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte
- 'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
- Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
- oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website
- oXMLHTTP.Send 'send request
- 'Wait for request to finish
- Do While oXMLHTTP.readyState <> 4
- DoEvents
- Loop
- oResp = oXMLHTTP.responseBody 'Returns the results as a byte array
- 'Create local file and save results to it
- vFF = FreeFile
- If Dir(vLocalFile) <> "" Then Kill vLocalFile
- Open vLocalFile For Binary As #vFF
- Put #vFF, , oResp
- Close #vFF
- 'Clear memory
- Set oXMLHTTP = Nothing
- End Function
- Sub TestingTheCode()
- 'This will save the Google logo to your hard drive, insert it into the
- ' active spreadsheet, then delete the local file
- SaveWebFile "http://www.google.com/intl/en/images/logo.gif", "C:GoogleLogo.gif"
- ActiveSheet.Pictures.Insert "C:GoogleLogo.gif"
- Kill "C:GoogleLogo.gif"
- End Sub
- For i = 1 to lastRow
- cellAddress = Replace(Range("A" & i).Hyperlinks(1).Address, "mailto:", "")
- 'Something to get the file name from the whole file name here
- SaveWebFile cellAddress, destinationFolder & filename
- Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement