Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate IE Download from jsp page - follow link after logon

Status
Not open for further replies.

rangsant

Programmer
Jan 15, 2007
5
FR
Hi,

I'm trying to retrieve a csv file from a jsp web page and need to automate the following:

1)Logon (which I have managed)

2)Click on one of the links on the screen after logging on (tried sendkeys and navigate but don't seem to work)

3)Select download date range from combo box on next screen

4)Submit, download window pops up

5)Choose Save file to a folder

I'm new to programming in VBA and any help/guidance would be greatly appreciated!!
 
rangsant,
This might shed some light on numbers 2 and 3.

faq707-6399 How to automate web forms from VBA using Internet Explorer

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Thanks, CMP. That's very helpful.

Got to the last bit (no.5) and stuck where a filedownload dialog box pop up (the one with options: Open, Save, Cancel, More Info)

Would be great if you can enlighten me about controlling that sort of pop-up.

Please reply to that bit on:

Many thanks in advance.

RT
 
set objXMLHTTP = CreateObject("msxml2.XMLHTTP")
' method, url, asynchronous, username, password
objXMLHTTP.open "GET", " False
objXMLHTTP.send


if objXMLHTTP.status <> 200 then
' Log("Error. Status code: " & objXMLHTTP.status & ", " & objXMLHTTP.statustext & " " & URL)
msgbox "Error. Status code: " & objXMLHTTP.status & ", " & objXMLHTTP.statustext & " " & URL
'exit function
end if


set objStream = CreateObject("ADODB.Stream")
objStream.Type = 1 ' 1 = binary, 2 = Text (default = 2)
objStream.Open
objStream.type = 1
objStream.write objXMLHTTP.responseBody
TimeEnd = Now
objStream.savetofile "c:\hsp12.exe", 1
BytesRcvd = objStream.size
BytesExpect = objXMLHTTP.getResponseHeader("Content-Length")
objStream.Close


set objStream = Nothing
set objXMLHTTP = Nothing
 
Thanks, mrmovie. I can't seem to get it to work though.

Doing the standard IE methods, I've managed to automate navigation through to the page where I input the date range of the data required then click submit for the csv file.

I pasted your codes after the bit where I got to the file download box and tried to modify the source but only got 'file not found' message.

Also tried using sendkeys "o" to open it in excel then save it but doesn't work for some reason...
 
yeah, sorry rangsant, i thought you might find my post interesting....i dont think it answers your specific question but demonstrates that if you know the location of the file you want from a website you can just go straight ahead and grab it without the need to the gui etc
 
yes, it certainly is a structure I have never seen and I'm sure it'll come handy at some stage. Cheers!
 
rangsant,
I've never tried to catch the popup but here are a couple of thoughts.

[tt]SendKeys[/tt] will work once the popup is displayed. I suspect you ran into a timing issue which is why it's not working for you.

One way to work around this is to use the Find Window API to allow your code to know when the dialog pops up, then you could use [tt]SendKeys[/tt]. If want to look at this route you could also look at the [tt]SenMessage[/tt] API in lieu of [tt]SendKeys[/tt].

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
you could try a AppActivate for the title of the window you are expecting checking for the return code of AppActivate and exiting the loop when it is found
 
Sorry for my slowness... Having a tough time learning to use API functions, especially when trying to learn from msdn...

I'd really appreciate if you can point me to some examples using API working with IE from Excel VBA.

Thanks again for your directions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top