VBA Select from dropdown in Internet Explorer

elt2jdavis

edit: I cleaned up the source code formatting and updated my VBA code. I'm no longer getting an error, but nothing is happening in my browser window (nothing selected, nothing clicked).

I have some VBA code that allows a user to enter information into a form in Excel. The code takes this information and generates an address to a page on our intranet. On that page there is a dropdown list to select export format and after a format is chosen the user can click to export the file.

The VBA code I have tried (and several variations) is below:

Public Sub window_Open(strLocation As String, Menubar As Boolean, height As Long, width As Long, resizable As Boolean)

With CreateObject("InternetExplorer.Application")
    .Visible = False
    .height = height
    .width = width
    .Menubar = Menubar
    .Visible = True
    .resizable = True
    .Navigate strLocation
End With

End Sub


    Private Sub OKButton_Click()
    Dim ProductionAddress As String
    ProductionAddress = "http://Collapsed"

    window_Open ProductionAddress, True, 800, 1000, False
        Dim ie As Object
        Set ie = CreateObject("InternetExplorer.Application")

        ie.Navigate ProductionAddress

        While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend

        ie.document.getelementbyid("ReportViewerControl_ctl01_ctl05_ctl00").Value = "EXCEL"

        Set objButton = ie.document.getelementbyid("ReportViewerControl_ctl01_ctl05_ctl01")
            objButton.Focus
            objButton.Click

    End Sub

The source code for the page I am attempting to navigate is below. Element for selecting EXCEL:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<style>
body, frameset, form {
    margin: 0px;
    padding: 0px;
}
.PageNumberText, input, button, select, table, body, frameset {
    font-size: 8pt;
    font-family: Verdana;
}
.ToolbarExport {
    display: inline;
}
.WidgetSet {
    height: 30px;
}
.ToolBarButtonsCell {
    padding-left: 6px;
}
.MenuBarBkGnd {
    background-color: #ECE9D8;
}
</style>
</head>
<body style="margin: 0px; overflow: auto;"><form name="ReportViewerForm" id="ReportViewerForm" action="ReportViewer.aspx?%2fProduction%2fWell+Daily+Production&amp;StartDate=01%2f01%2f2015+00%3a00%3a00&amp;EndDate=07%2f21%2f2015+00%3a00%3a00&amp;WellName=Acadia&amp;rs%3aParameterLanguage=&amp;rc%3aParameters=Collapsed" method="post"><table id="ReportViewerControl" style="width: 100%; height: 100%;" onclick="if (document.getElementById('ReportViewerControl_ctl00') != null) document.getElementById('ReportViewerControl_ctl00').ParametersController.HideActiveDropDown();" onactivate="if (document.getElementById('ReportViewerControl_ctl00') != null) document.getElementById('ReportViewerControl_ctl00').ParametersController.HideActiveDropDown();" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="MenuBarBkGnd"><div class="ToolBarButtonsCell"><div class="ToolbarExport WidgetSet"><table style="display: inline;" cellspacing="0" cellpadding="0"><tbody><tr><td height="28"><select name="ReportViewerControl$ctl01$ctl05$ctl00" title="Export Formats" id="ReportViewerControl_ctl01_ctl05_ctl00" onchange="document.getElementById('ReportViewerControl_ctl01_ctl05_ctl01').Controller.SetViewerLinkActive(document.getElementById('ReportViewerControl_ctl01_ctl05_ctl00').selectedIndex != 0);"><option value="EXCEL">Excel</option></select></td></tr></tbody></table></div></div></div></td></tr></tbody></table></form></body>
</html>

And the source code for the export element:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<style>
.DisabledLink {
    font-size: 8pt;
    font-family: Verdana;
    color: gray;
    text-decoration: none;
    cursor: default;
}
body, frameset, form {
    margin: 0px;
    padding: 0px;
}
.PageNumberText, input, button, select, table, body, frameset {
    font-size: 8pt;
    font-family: Verdana;
}
.ToolbarExport {
    display: inline;
}
.WidgetSet {
    height: 30px;
}
.ToolBarButtonsCell {
    padding-left: 6px;
}
.MenuBarBkGnd {
    background-color: #ECE9D8;
}
</style>
</head>
    <body style="margin: 0px; overflow: auto;"><form name="ReportViewerForm" id="ReportViewerForm" action="ReportViewer.aspx?%2fProduction%2fWell+Daily+Production&amp;StartDate=01%2f01%2f2015+00%3a00%3a00&amp;EndDate=07%2f21%2f2015+00%3a00%3a00&amp;WellName=Acadia&amp;rs%3aParameterLanguage=&amp;rc%3aParameters=Collapsed" method="post"><table id="ReportViewerControl" style="width: 100%; height: 100%;" onclick="if (document.getElementById('ReportViewerControl_ctl00') != null) document.getElementById('ReportViewerControl_ctl00').ParametersController.HideActiveDropDown();" onactivate="if (document.getElementById('ReportViewerControl_ctl00') != null) document.getElementById('ReportViewerControl_ctl00').ParametersController.HideActiveDropDown();" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="MenuBarBkGnd"><div class="ToolBarButtonsCell"><div class="ToolbarExport WidgetSet"><table style="display: inline;" cellspacing="0" cellpadding="0"><tbody><tr><td height="28"><a title="Export" class="DisabledLink" id="ReportViewerControl_ctl01_ctl05_ctl01" onmouseover="this.Controller.OnLinkHover();" onmouseout="this.Controller.OnLinkNormal();" onclick="&#10;var formatDropDown = document.getElementById('ReportViewerControl_ctl01_ctl05_ctl00');&#10;if (formatDropDown.selectedIndex == 0)&#10;return false;&#10;window.open(document.getElementById('ReportViewerControl').ClientController.m_exportUrlBase + encodeURIComponent(formatDropDown.value), '_blank')&#10;formatDropDown.selectedIndex = 0;&#10;document.getElementById('ReportViewerControl_ctl01_ctl05_ctl01').Controller.SetViewerLinkActive(document.getElementById('ReportViewerControl_ctl01_ctl05_ctl00').selectedIndex != 0);return false;" href="#"><script type="text/javascript">
                            document.getElementById('ReportViewerControl_ctl01_ctl05_ctl01').Controller = new ReportViewerLink("ReportViewerControl_ctl01_ctl05_ctl01", false, "ActiveLink", "DisabledLink", "", "", "");
                        </script>Export</a></td></tr></tbody></table></div></div></div></td></tr></tbody></table></form></body>
</html>

Thanks!

SierraOscar

You need to actually navigate to the page first in order to load the document - then use the below code:

ie.Document.GetElementByID("ReportViewerControl_ctl01_ctl05_ctl00").Value = "EXCEL"

Use the option that is inside the <option> tag.


To navigate:

ie.Navigate ProductionAddress

While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend

ie.Document.GetElementByID("ReportViewerControl_ctl01_ctl05_ctl00").Value = "EXCEL"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

VBA Select Item from List in Internet Explorer

Unable to select a value from dropdown inside dynamic webtable in Internet Explorer

Toggle Internet Explorer Proxy from Excel VBA

Can change VBA explorer way to select dropdown list?

Run my VBA code from a existing (opened) internet explorer page

Changing browser from internet explorer to Microsoft edge in VBA script

Excel VBA: How to copy value of a field from Internet Explorer

VBA: Copy data/text from an existing open Internet Explorer tab

Auto save PDF file from Internet Explorer window using VBA

Removing item from select list (Internet Explorer 10)

Unable to select from dropdown in selenium using vba

vba internet explorer delete object

VBA - Addressing Internet Explorer tabs

Dropdown list showing vertically in Internet explorer

How do I select a radio button on an Internet Explorer page using VBA?

Get data from Internet Explorer

What's the Internet Explorer keyboard shortcut to select "Save as" from the "Do you want to open or save ... from ...?"-dialog?

Automatically filling Internet Explorer inputbox - VBA in MSP

Change Internet Explorer encoding using VBA

Excel VBA Error 462 With Internet Explorer

How to click a button in Internet Explorer using VBA

VBA UI Automation - Internet Explorer "Save As"

VBA - terminating Internet Explorer processes via Shell

click on link text in internet explorer using vba

Excel VBA Internet explorer click button with no ID

vba intercept internet explorer link click

VBA Internet Explorer Webpage Link Selection

VBA: set HTML as Internet Explorer object ERROR

Control an Element in invisible Internet Explorer vba