Saving a File from Internet Explorer
Posted by admin - Jul 12, 2008 ADODB, Anshoo Arora, Articles, File System, QTips, Yaron Assa 0 0 Views : 273 Receive Updates For This Category
Article Tools
- Print this page
- Add Comment
- Send to Friend
- Last Updated on :
Jul 17, 2011
Anshoo Arora has a great QTip for saving a file via Internet Explorer. This will produce similar results to manually right-clicking a link and choosing “Save as”:
'Simulate a web query
Set WinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
If WinHttp Is Nothing Then Set WinHttp = CreateObject("WinHttp.WinHttpRequest")
WinHttp.Open "GET", "http://www.website.com/Documnet_i_want_to_save.pdf", False
WinHttp.Send
'Get the response
arrArray = WinHttp.ResponseBody
Set WinHttp = Nothing
'Write the response
On Error Resume Next
Set oADO = CreateObject("ADODB.Stream")
If oADO Is Nothing Then
'Write via FSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile("c:\Documnet_i_want_to_save.pdf", 2, True)
sData = ""
sBuffer = ""
For iCount = 0 to UBound(arrArray)
oTextFile.Write Chr(255 And Ascb(Midb(arrArray,iCount + 1, 1)))
Next
oTextFile.Close
Else
'Write via ADO
oADO.Type = 1
oADO.Open
oADO.Write arrArray
oADO.SaveToFile "c:\Documnet_i_want_to_save.pdf", 2
oADO.Close
End If
Set oADO = Nothing
Set oTextFile = Nothing
Set oFSO = Nothing
Thanks Anshoo for this great QTips


