【发布时间】:2018-12-31 06:33:35
【问题描述】:
我有点问题。我希望一些VBA大师可以帮助我。我有一个网站,其中包含我希望能够选择的下拉选项。现在我的代码关闭了,我不确定我做错了什么。我查看了该网站,试图找出我做错了什么,但没有发现可以直接回答我的问题。任何帮助将不胜感激。
这是我所拥有的:
Private Sub CMReportExport()
Dim IEapp As Object
Dim WebUrl As String
Dim yearList As Object
Dim prefixList As Object
Dim versionList As Object
Set IEapp = CreateObject("InternetExplorerMedium.Application")
'Set IEapp = CreateObject("InternetExplorer.Application")
WebUrl = "http://reporthub/Enterprise/Pages/Report.aspx?ItemPath=%2fSupply+Chain%2fProduction%2fContribution+Margin%2fNonFood%2fNonFood+CM+RetailCat"
With IEapp
.Silent = True
.Visible = True
.navigate WebUrl
End With
While IEapp.Busy Or IEapp.readyState < 4: DoEvents: Wend '<== Ensure page loaded
Set yearList = IEapp.document.querySelectorAll("#ctl32_ctl04_ctl03_ddValue option") '<==apply CSS selector to get nodeList
Set prefixList = IEapp.document.querySelectorAll("#ctl32_ctl04_ctl05_ddValue option")
Set versionList = IEapp.document.querySelectorAll("#ctl32_ctl04_ctl07_ddValue option")
yearList.item(2).Selected = True 'Index into nodeList e.g. second item is at index 2 = year 2018
prefixList.item(2).Selected = True
versionList.item(1).Selected = True
'Set IEapp.getElementById("ctl32_ctl04_ctl03_ddValue").selectedvalue = 2 'Year
'Set IEapp.getElementById("ctl32_ctl04_ctl05_ddValue").selectedvalue = DA 'Prefix
'Set IEapp.getElementById("ctl32_ctl04_ctl07_ddValue").selectedvalue = 1 'Version
End Sub
HTML 元素(一个块)如下:
<tr>
<td class="ParamLabelCell"><label for="ctl32_ctl04_ctl03_ddValue"><span>Year</span></label>
</td>
<td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl32_ctl04_ctl03">
<select name="ctl32$ctl04$ctl03$ddValue" onchange="javascript:setTimeout('__doPostBack(\'ctl32$ctl04$ctl03$ddValue\',\'\')', 0)" id="ctl32_ctl04_ctl03_ddValue" disabled="disabled">
<option selected="selected" value="0"><Select a Value></option>
<option value="1">2019</option>
<option value="2">2018</option>
<option value="3">2017</option>
<option value="4">2016</option>
<option value="5">2015</option>
</select>
</div></td><td class="InterParamPadding"></td><td class="ParamLabelCell"><label for="ctl32_ctl04_ctl05_ddValue"><span disabled="disabled">Offer</span></label></td><td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl32_ctl04_ctl05">
<select name="ctl32$ctl04$ctl05$ddValue" onchange="javascript:setTimeout('__doPostBack(\'ctl32$ctl04$ctl05$ddValue\',\'\')', 0)" id="ctl32_ctl04_ctl05_ddValue" disabled="disabled" class="EmptyDropDown">
</select>
</div>
</td>
</tr>
<tr IsParameterRow="true">
<td class="ParamLabelCell"><label for="ctl32_ctl04_ctl07_ddValue"><span disabled="disabled">Version</span></label></td>
<td class="ParamEntryCell" style="padding-right:0px;"><div id="ctl32_ctl04_ctl07">
<select name="ctl32$ctl04$ctl07$ddValue" id="ctl32_ctl04_ctl07_ddValue" disabled="disabled" class="EmptyDropDown">
</tr>
【问题讨论】: