PDA

View Full Version : click a button in a dropdown menu on webpage to download sth using vba



henryshen
12-04-2014, 05:09 PM
hi, im a noobie on vba programming. i hv copy and pasted some codes from somewhere else of navigating an url and submiting a form to enter userID and password. but i got stucked when i was going to use vba codes to download a report generated by the website, which means there is no static url to the file that i need to download. What I want to do is write a code of trying to click some buttons on the page as i click to download something physically on IE. much appreciated in advance, anybody can help me?
12585
As is shown, what i normally do is click on that image of a soft disk, and then there appears a dropdown list. then click on “excel” to download an excel spreadsheet.
the html code of that soft disk and excel option is as below:

<table id="reportViewer_ctl05_ctl04_ctl00_Button" title="Export"><tr><td><a id="reportViewer_ctl05_ctl04_ctl00_ButtonLink" title="Export" alt="Export" href="javascript:void(0)" style="text-decoration:none;"><img id="reportViewer_ctl05_ctl04_ctl00_ButtonImg" src="/Reserved.ReportViewerWebControl.axd?OpType=Resource&amp;Version=11.0.3366.16&amp;Na me=Microsoft.Reporting.WebForms.Icons.ExportDisabled.gif" alt="Export" style="border-style:None;height:16px;width:16px;" /><span style="width:5px;text-decoration:none;"> </span><img id="reportViewer_ctl05_ctl04_ctl00_ButtonImgDown" src="/Reserved.ReportViewerWebControl.axd?OpType=Resource&amp;Version=11.0.3366.16&amp;Na me=Microsoft.Reporting.WebForms.Icons.ArrowDownDisabled.gif" alt="Export" style="border-style:None;height:6px;width:7px;margin-bottom:5px;" /></a></td></tr></table>

....

<div style="border:1px transparent Solid;">
<a title="Excel" alt="Excel" onclick="$find('reportViewer').exportReport('EXCELOPENXML');" href="javascript:void(0)" style="color:#3366CC;font-family:Segoe UI,Tahoma,Arial;font-size:11px;padding:3px 8px 3px 8px;display:block;white-space:nowrap;text-decoration:none;">Excel</a></div>

henryshen
12-04-2014, 05:28 PM
what i was trying to do is like:


With ie
Set dmt1 = .document
dmt1.getelementbyid("reportViewer_ctl05_ctl04_ctl00_ButtonImg").Click
End With

since that "excel" option label does not have an ID or name, i cannot capture it.

SamT
12-05-2014, 09:54 AM
The only part of the code that you show that is of use to you is
onclick="$find('reportViewer').exportReport('EXCELOPENXML');" href="javascript:void(0)"and even that is only a piece of what you need.

Save the page as Web Page Complete (? Not sure about IE's Save) and look in the _Files folder for a js with "ReportViewer" in it.

henryshen
12-06-2014, 06:34 PM
hi, Sam, i would like to thank you for your reply firsr. i just went through all js from the _files folder and found only one js with "reportviewer" in it which i attached it. i dont think it is of use.

["Error_Title_0x80048313"]='Reporting Error';errorTable["Error_Message_0x80048313"]='The SOAP endpoint used by the ReportViewer control could not be accessed.
actually what i really want to do is get the generated excel file from report template in the CRM portal and then copy and paste raw data into the worksheet that contains lots of macro to do the analysis. i hope to make the process as simple as possible better by just one click. now i can easily get into the report template by one click but i cannot trigger the save as or open window to open that excel file which i believe is already there on the server if you know what i mean. since the CRM portal is not like the other webpages. it hides lots of html codes. so far, i've almost given up keeping trying this, but thank you anyway.

SamT
12-06-2014, 07:20 PM
:dunno

Good luck