简体   繁体   English

使用excel vba标记Internet Explorer中的所有复选框

[英]mark all check boxes in internet explorer using excel vba

I'm trying to create excel macro which will mark 75 check boxes in a certain table on internet explorer page 我正在尝试创建Excel宏,该宏将在Internet Explorer页面的某个表中标记75个复选框

the code of that table is : 该表的代码是:

    <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>

and so on I have tried various ways but it doesn't want to play 等等,我尝试了各种方法,但是它不想玩

With IE.document.getElementsByName("ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes")
    .Item.Click
end with

and

With IE.document.getElementsByName("checkBoxlist(ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes)")
.Item(0).Checked = True 'Entered
End With

and

For Each htmlelement In IE.document.getElementsByName("ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes")
htmlelement.Item(0).Click
Next htmlelement

Thanks in advance for any help or leads :) 在此先感谢您的帮助或潜在客户:)

I am making an assumption here that the checkboxes that have an id like this: 我在这里假设ID为如下所示的复选框:

ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_0

Have an identifier that begins at 0, as above, and increments by 1 to 74 (corresponding to your request for 75 checkboxes). 如上所述,具有一个以0开头并以1到74递增的标识符(对应于您要求的75个复选框)。

If that is the case, something like this may work: 在这种情况下,可能会发生以下情况:

    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

Of course you must be sure you have set ie appropriately, navigated to the page, etc. 当然,您必须确保已正确设置, ie导航至页面等。

This code will first grab and click 此代码将首先获取并单击

ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_0

Then i increments by 1, so it will grab and click 然后我加1,所以它将抓住并单击

ctl00_MasterMain_ucGenConfig_ucConfigContainer_ucConfigPopup_cblSchemes_1

And so on, to 74. 依此类推,直到74。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM