PDA

View Full Version : VBA code to download files from internet under Chrome



codeperson
08-27-2013, 10:42 PM
I have a VBA code to download files from internet. The code automatically chooses Internet Explorer to open the URLs and to download the pdf files. I would like the code to automatically choose Google Chrome instead of IE to open the URLs to download files. But I don't know how to modify the code. Please help if you know.

For your reference, the code I'm using is:



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

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


'Returns the results as a byte array
oResp = oXMLHTTP.ResponseBody

'Create a local file and save result to it
vFF = FreeFile

If Dir(vLocalFile) <> "" Then Kill vLocalFile

Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF

Set oXMLHTTP = Nothing
End Function

Edited to add Code Tags. (The # button)

SamT
08-28-2013, 08:47 AM
I did some research on the web and the only answers I could find say that you can open Chrome with a Shell script, but you can't automate Chrome to do anything else.

If FireFox will work for you, try this link from our archives: Solved: Firefox Questions (http://www.vbaexpress.com/forum/showthread.php?6726-Solved-Firefox-Questions)

codeperson
08-28-2013, 03:38 PM
Thanks!