我试图创建excel宏,它会在Internet Explorer页面的某个表中标记75个复选框
该表的代码是:
<TABLE id=ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes border=0><TBODY>
<TR>
<TD><INPUT id=ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_0 type=checkbox name=ctl00$MasterMain$ucGenConfig$ucConfigContainer$ucConfigPopup$cblSchemes$0><LABEL for=ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_0>Start</LABEL></TD></TR>
<TR>
<TD><INPUT id=ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_1 type=checkbox name=ctl00$MasterMain$ucGenConfig$ucConfigContainer$ucConfigPopup$cblSchemes$1><LABEL for=ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_1>Start2</LABEL></TD></TR>
<TR>
<TD><INPUT id=ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_2 type=checkbox name=ctl00$MasterMain$ucGenConfig$ucConfigContainer$ucConfigPopup$cblSchemes$2><LABEL for=ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_2>Default</LABEL></TD></TR>
<TR>
等等 我尝试了各种各样的方法,但它并不想玩
With IE.document.getElementsByName("ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes")
.Item.Click
end with
和
With IE.document.getElementsByName("checkBoxlist(ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes)")
.Item(0).Checked = True 'Entered
End With
和
For Each htmlelement In IE.document.getElementsByName("ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes")
htmlelement.Item(0).Click
Next htmlelement
提前感谢任何帮助或潜在客户:)
答案 0 :(得分:1)
我在这里假设复选框的ID如下:
ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_0
标识符从0开始,如上所述,并以1到74递增(对应于您对75个复选框的请求)。
如果是这种情况,这样的事情可能有效:
Dim sBaseName As String
Dim i As Integer
'The base id of the checkboxes
sBaseName = "ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_"
For i = 0 To 74 '75 checkboxes
ie.Document.getElementByID(sBaseName + CStr(i)).Click
Next i
当然,您必须确保已正确设置ie
,导航到该页面等。
此代码首先抓取并单击
ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_0
然后我增加1,所以它会抓住并点击
ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_1
等等,到74岁。