PDA

View Full Version : Solved: web navigation



CodeNinja
07-24-2012, 02:33 PM
I am trying to pull a series of reports from the web using VBA.

I have successfully logged on to the account, navigated to where I see the report button, now I need to figure out the element I need to click to open the report and how to save the report to my hard drive.

Attached is a screen shot of the web page...

I am trying to "Click" on the summary report in the upper right corner...

Attached is the page source.

I would also like to be able to "click" on the July 09,2010 tab and click the same summary report.

Once I figure all this out, I believe I can do everything else I need.

Thanks for your help...

The code I am using to log on etc is as follows (I have deleted the password/username etc):

Sub test()
Dim Doc As HTMLDocument
Dim ie As InternetExplorer
Dim loginForm As HTMLFormElement
Dim usernameInputBox As HTMLInputElement
Dim passwordInputBox As HTMLInputElement
Dim signinbutton As HTMLImg
Dim sURL As String


sURL = "test2.hyattselectreports.lraqa.com/" '"https://test2.lraqa.com/"


Set ie = New InternetExplorer
ie.navigate sURL
ie.Visible = True

While ie.Busy
DoEvents
Wend


Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE


Set Doc = ie.document
On Error Resume Next

Set loginForm = Doc.forms(0)
Set usernameInputBox = loginForm.elements("username")
usernameInputBox.Value = "" 'I have deleted this for security reasons

Set passwordInputBox = loginForm.elements("password")
passwordInputBox.Value = "" 'I have deleted this for security reasons

loginForm.elements("LoginButton").Click




Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy
DoEvents
Loop


'************************************************************************** *****
' will have to loop through all properties listed in a column on sheet 1 or so *
'************************************************************************** *****
ie.navigate "http://test2.hyattselectreports.lraqa.com/index.php?page=&propid=" & Sheet1.Cells(1, 1)
'I put 33808 in cell a1 ... I will do this as a loop and populate the appropriate cells with the property id's


Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy
DoEvents
Loop



'need code here to "click" on the summary report button to navigate to that page... Thanks!




End Sub




Thanks for any help/suggestions.

Josh / CodeNinja.

CodeNinja
07-24-2012, 02:35 PM
Here is the source of the webpage...

snb
07-25-2012, 02:08 AM
Why don't you use a webquery ?

https://test2.hyattselectreports.lraqa.com/index.php?page=&propid=33819

CodeNinja
07-25-2012, 08:03 AM
WebQuery will not work for me (I think...) as I need to programatically go through and import hundreds of files from different locations within the website.

Regardless, I would much rather learn more about VBA by doing this with code.

Ideally, I would like to find a way to identify the individual elements by some kind of loop and feedback... IE something like:
for i = 1 to elements.count
msgbox(element.id/name/whatever & vblf & i)
next i

That way I could loop through and find the element I am looking for easily, but I have not found any way to do that...

I am at a bit of a loss and almost ready to give up on it though :(

Help is greatly appreciated... especially the kind that helps me learn.

Thanks,

Josh / CodeNinja.

omnibuster
07-25-2012, 10:39 AM
It has always helped me.

http://www.tek-tips.com/faqs.cfm?fid=6399

omnibuster
07-25-2012, 10:48 AM
It has always helped me.

http://www.tek-tips.com/faqs.cfm?fid=6399

CodeNinja
07-25-2012, 11:28 AM
Thanks omnibuster... That looks like it could be of great help.

CodeNinja
07-25-2012, 01:43 PM
After a whole bunch of experimentation, I have figured out how to navigate to the reports I want. My code opens a new tab with the PDF format report just as I want it to. :joy:

Now my challenge is to save the pdf report to a folder I designate. Any suggestions on the syntax to save a document?

Thanks,

Josh / CodeNinja.