PDA

View Full Version : HELP with VB/HTML code.



vvSTRIDEvv
12-20-2010, 08:04 AM
I'm currently working to automate some reporting functions. The goal is to have a report which is normally manual. Populate with data stored on our company extranet website.

There is a section of the site where the user can export reports based on (Location, Department, Date).
So far I've figured out the ID's and code for most of the page. However, I'm hitting a wall. Once the criteria is entered the user must click on a link "Export". I can't seem to code VB to click this link.

Here is some of the code...link error at the bottom:


Dim IE As Object
Set IE = CreateObject("internetexplorer.application")
With IE
.Visible = False
.navigate ("://website")
While .Busy Or .readyState <> 4: DoEvents: Wend
.document.getelementbyid("ctl00_cphMain_ctrlLogin_user_new").Focus
.document.getelementbyid("ctl00_cphMain_ctrlLogin_user_new").Value = "name"
.document.getelementbyid("ctl00_cphMain_ctrlLogin_pw_new").Focus
.document.getelementbyid("ctl00_cphMain_ctrlLogin_pw_new").Value = "password"
.document.all("ctl00_cphMain_ctrlLogin_btnLogin_new").Click


While .Busy Or .readyState <> 4: DoEvents: Wend
Debug.Print .LocationURL
End With


Set IE = CreateObject("internetexplorer.application")
With IE
.Visible = True
.navigate ("//website")
While .Busy Or .readyState <> 4: DoEvents: Wend

.document.getelementbyid("ctl00_cphMain_Label1").Focus
.document.all("ctl00_cphMain_Label1").Click
.document.getelementbyid("ctl00_cphMain_Label2").Focus
.document.getelementbyid("ctl00_cphMain_lbDepartment").Value = "284"
.document.getelementbyid("ctl00_cphMain_Label3").Focus
.document.getelementbyid("ctl00_cphMain_txbFromDate").Value = "12-08-2010"
.document.all("ctl00_cphMain_btnRender").Click

End With

With IE

While .Busy Or .readyState <> 4: DoEvents: Wend
Debug.Print .LocationURL
.document.getelementbyid("ctl00_cphMain_rptView_ctl01_ctl05_ctl00").Focus
.document.all("ctl00_cphMain_rptView_ctl01_ctl05_ctl00").Click
.document.getelementbyid("ctl00_cphMain_rptView_ctl01_ctl05_ctl00").Value = "EXCEL"
.document.all("ReportFramectl00_cphMain_rptView").Click


.document.all("oReportDiv").Click

End With
I've also attached the source, and help would be HUGE!!!

Shred Dude
12-20-2010, 08:43 AM
crosspost?

http://www.excelforum.com/excel-programming/757027-handling-html-dialog-box-to-download-file-from-website.html

Celelond
12-20-2010, 08:49 AM
Maybe counting the links? If it's one link you set.

I used

ie.Document.all.tags("a").Item(X).href

X would be the count, counting from 0.

Then maybe set what it finds as a submitbutton?

I am sure there is something that would suit your needs more, just something that I used in that situation.

Hope that helps

vvSTRIDEvv
12-20-2010, 10:31 AM
Shred, oddly this is not a crosspost, though the reference thread is very similar.

Still not having any luck. I can not locate the Id for the "Export" link anywhere.

Shred Dude
12-20-2010, 10:37 AM
Then maybe someone else in your Grocery company is working on the same problem. The HTML code snippet posted on the other site is found within the full HTML you posted. Same webpage. They're trying to export CSV, and you're trying to dump an Excel format.

Use "Find" in your word document of the HTML, or in the View Source window for the HTML, or better yet paste the HTML into an editor like Notepad++, and you'll find every reference to any word you search for.

good luck jvalentine

vvSTRIDEvv
12-20-2010, 01:48 PM
Ok, well I'm hitting another wall. I've located the "Export" link, the export link does indeed click, opens a new window with the correct address, then immediately, it closes. I'm wanting to view the dialog box, but it does not pull up.

Do I need to include some code to allow for the dialog box?


.document.all("ctl00_cphMain_rptView_ctl01_ctl05_ctl01").Focus
IE.document.all("ctl00_cphMain_rptView_ctl01_ctl05_ctl01").Click