VBA IE 控件在 IE 中没有名称或 ID 标签的单选按钮
VBA IE Control Radio button that does not have a name or ID tag in IE
我正在尝试获取我的一些代码来更改内部网页上的单选按钮,但是,页面的编写方式我想要的元素没有特定的 ID。这是代码示例:
<div align="center" id="divControls">
<form id="frmSearch" name="frmSearch" method="POST">
<table cellpadding="0" cellspacing="0" class="exec_tbl align_vc">
<tr>
<td class="exec_ltxt"><input type="radio" name="search" value=1 checked=checked onclick="collapse('submit');searchOptions();" /> Agent Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=2 onclick="expand('submit');searchOptions();" /> Team Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=3 onclick="expand('submit');searchOptions();" /> Manager Search</td>
<td class="exec_ltxt"><input type="radio" name="search" id='searchlob' value=4 onclick="expand('submit');searchOptions();" /> LoB Search</td>
</tr>
</table>
</form>
</div>
我只需要让单选按钮点击值=2(团队搜索)。
我尝试使用的 VBA 是:
Sub Attendance_RoundedRectangle2_Click()
sCSVLink = "webpage"
sfile = "csvexport.php"
ssheet = "Sheet10"
Dim appIE As InternetExplorerMedium
Dim Obj As Object
On Error Resume Next
Application.ScreenUpdating = False
Set appIE = New InternetExplorerMedium
Set ieRadio = IE.document.all
sURL = "webpage"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .document
End With
Application.Wait Now + TimeValue("00:00:02")
appIE.document.all.Item("divControls")(3).Checked = True
appIE.document.getElementByid("divControls").Value = "2"
End Sub
我绝不是专业人士,我正在尝试将所有内容拼凑起来,非常感谢我能得到的任何帮助!
已更新HTML
<div align="right"><a href="index.php?logout=1">logout</a></div><h1 class="font_2 & uline & center" style="color:#909090;">Reporting</h1>
<div align="center" id="divControls">
<form id="frmSearch" name="frmSearch" method="POST">
<table cellpadding="0" cellspacing="0" class="exec_tbl align_vc">
<tr>
<td class="exec_ltxt"><input type="radio" name="search" value=1 checked=checked onclick="collapse('submit');searchOptions();" /> Agent Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=2 onclick="expand('submit');searchOptions();" /> Team Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=3 onclick="expand('submit');searchOptions();" /> Manager Search</td>
<td class="exec_ltxt"><input type="radio" name="search" id='searchlob' value=4 onclick="expand('submit');searchOptions();" /> LoB Search</td>
</tr>
<tr>
<td class="exec_ltxt" colspan="3"><div id="divSearchOption" align="center" style="display:inline;width:100%;"></div></td>
<td class="exec_ctxt"><input id="submit" type="button" value="Submit" style="display:none;" onclick="submitButton();"></td>
</tr>
<tr>
<td class="exec_rtxt">Start Date:</td>
<td class="exec_ltxt">
<input id="sDate" name="sDate" type="text" size="9" value="2014-01-08" onchange="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" onblur="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" />
<img src="icon_pickdate.gif" id="start_date_button" alt="date picker" />
</td>
<td class="exec_rtxt">End Date:</td>
<td class="exec_ltxt">
<input id="eDate" name="eDate" type="text" size="9" value="2015-01-08" onchange="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" onblur="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" />
<img src="icon_pickdate.gif" id="end_date_button" alt="date picker" />
</td>
</tr>
</table>
<input id="uid" name="uid" type="hidden" value="agent" />
</form>
</div>
<div id="divTeamTable" align="center"></div>
<br/>
<div align="center" id="divAgentData"></div>
我遗漏的唯一信息是 header,其中包含几个不应影响 VBA.
的 javascript 链接
您不需要使用 Application.Wait 暂停 运行 宏,您可以在宏导航到 URL 时让事件先发生,然后再尝试工作通过 DOM
在 With...End With 块中,在 .Visible = True 行之前添加:
Do
DoEvents
Loop Until .ReadyState = 4
.Document.getElementsByTagName("input")(1).Checked = True
删除这些代码行,因为它们不再有任何用途:
Set ieRadio = IE.document.all
Set HTMLDOC = .document
Application.Wait Now + TimeValue("00:00:02")
appIE.document.all.Item("divControls")(3).Checked = True
appIE.document.getElementByid("divControls").Value = "2"
我认为这可能会有所帮助,虽然效率不高,但有效。
set inputObjs=appIE.document.getElementByTag("input")
for each obj in inputObjs
if(obj.value=2 ) then obj.click
next
我正在尝试获取我的一些代码来更改内部网页上的单选按钮,但是,页面的编写方式我想要的元素没有特定的 ID。这是代码示例:
<div align="center" id="divControls">
<form id="frmSearch" name="frmSearch" method="POST">
<table cellpadding="0" cellspacing="0" class="exec_tbl align_vc">
<tr>
<td class="exec_ltxt"><input type="radio" name="search" value=1 checked=checked onclick="collapse('submit');searchOptions();" /> Agent Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=2 onclick="expand('submit');searchOptions();" /> Team Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=3 onclick="expand('submit');searchOptions();" /> Manager Search</td>
<td class="exec_ltxt"><input type="radio" name="search" id='searchlob' value=4 onclick="expand('submit');searchOptions();" /> LoB Search</td>
</tr>
</table>
</form>
</div>
我只需要让单选按钮点击值=2(团队搜索)。
我尝试使用的 VBA 是:
Sub Attendance_RoundedRectangle2_Click()
sCSVLink = "webpage"
sfile = "csvexport.php"
ssheet = "Sheet10"
Dim appIE As InternetExplorerMedium
Dim Obj As Object
On Error Resume Next
Application.ScreenUpdating = False
Set appIE = New InternetExplorerMedium
Set ieRadio = IE.document.all
sURL = "webpage"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .document
End With
Application.Wait Now + TimeValue("00:00:02")
appIE.document.all.Item("divControls")(3).Checked = True
appIE.document.getElementByid("divControls").Value = "2"
End Sub
我绝不是专业人士,我正在尝试将所有内容拼凑起来,非常感谢我能得到的任何帮助!
已更新HTML
<div align="right"><a href="index.php?logout=1">logout</a></div><h1 class="font_2 & uline & center" style="color:#909090;">Reporting</h1>
<div align="center" id="divControls">
<form id="frmSearch" name="frmSearch" method="POST">
<table cellpadding="0" cellspacing="0" class="exec_tbl align_vc">
<tr>
<td class="exec_ltxt"><input type="radio" name="search" value=1 checked=checked onclick="collapse('submit');searchOptions();" /> Agent Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=2 onclick="expand('submit');searchOptions();" /> Team Search</td>
<td class="exec_ltxt"><input type="radio" name="search" value=3 onclick="expand('submit');searchOptions();" /> Manager Search</td>
<td class="exec_ltxt"><input type="radio" name="search" id='searchlob' value=4 onclick="expand('submit');searchOptions();" /> LoB Search</td>
</tr>
<tr>
<td class="exec_ltxt" colspan="3"><div id="divSearchOption" align="center" style="display:inline;width:100%;"></div></td>
<td class="exec_ctxt"><input id="submit" type="button" value="Submit" style="display:none;" onclick="submitButton();"></td>
</tr>
<tr>
<td class="exec_rtxt">Start Date:</td>
<td class="exec_ltxt">
<input id="sDate" name="sDate" type="text" size="9" value="2014-01-08" onchange="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" onblur="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" />
<img src="icon_pickdate.gif" id="start_date_button" alt="date picker" />
</td>
<td class="exec_rtxt">End Date:</td>
<td class="exec_ltxt">
<input id="eDate" name="eDate" type="text" size="9" value="2015-01-08" onchange="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" onblur="if (document.getElementById('searchlob').checked != true) { searchOptions(); }" />
<img src="icon_pickdate.gif" id="end_date_button" alt="date picker" />
</td>
</tr>
</table>
<input id="uid" name="uid" type="hidden" value="agent" />
</form>
</div>
<div id="divTeamTable" align="center"></div>
<br/>
<div align="center" id="divAgentData"></div>
我遗漏的唯一信息是 header,其中包含几个不应影响 VBA.
的 javascript 链接您不需要使用 Application.Wait 暂停 运行 宏,您可以在宏导航到 URL 时让事件先发生,然后再尝试工作通过 DOM
在 With...End With 块中,在 .Visible = True 行之前添加:
Do
DoEvents
Loop Until .ReadyState = 4
.Document.getElementsByTagName("input")(1).Checked = True
删除这些代码行,因为它们不再有任何用途:
Set ieRadio = IE.document.all
Set HTMLDOC = .document
Application.Wait Now + TimeValue("00:00:02")
appIE.document.all.Item("divControls")(3).Checked = True
appIE.document.getElementByid("divControls").Value = "2"
我认为这可能会有所帮助,虽然效率不高,但有效。
set inputObjs=appIE.document.getElementByTag("input")
for each obj in inputObjs
if(obj.value=2 ) then obj.click
next