|
楼主 |
发表于 2010-3-6 15:44
|
显示全部楼层
用XMLHTTP下载GOOGLE图标的代码
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 |
|