我正在尝试根据excel文件中的信息填写在线表格。但是我陷入一个问题。我必须从组合框中选择一个选项,该选项应将我带到一个弹出窗口以允许多个选择。当我选择它时,弹出窗口不会打开。组合框中只写有“多项选择”。您能在这个问题上给我建议吗?
以下是html代码的相关区域:
<select name="psDelimSystemIDs" onchange="CheckSelectMulti(this,"4609","");">
<option value="^^"></option>
<option value="^^395^^">Option1</option>
<option value="^^404^^">...Option2</option>
<option value="^^567^^">...Option3</option>
<option value="^^409^^">...Option4 & 1</option>
<option value="^^416^^">...Option5 & 1</option>
<option value="^^413^^">...option6</option>
<option value="^^417^^">...Option 7</option>
<option value="^^396^^">Option 8</option>
<option value="^^426^^">...Option9 & Console</option>
<option value="^^430^^">...Option10</option>
<option value="^^436^^">...Option11</option>
<option value="^^423^^">...Option12</option>
<option value="^^397^^">Option13</option>
<option value="^^398^^">Option14</option>
<option value="^^469^^">...Option15 & Controls</option>
<option value="^^472^^">...Option16</option>
<option value="^^558^^">...Option17</option>
<option value="^^478^^">...Option18</option>
<option value="^^734^^">...Option19</option>
<option value="^^479^^">...Option20</option>
<option value="^^491^^">...Option21</option>
<option value="^^399^^">Option22</option>
<option value="^^401^^">Option23</option>
<option value="^^629^^">Option24</option>
<option value="^^630^^">Option25</option>
<option>----------- Select Multiple Systems -----------</option>
</select>
这是我的代码:
If ThisWorkbook.Sheets("sheet1").Range("f2").Value = "Option1" Then IE.document.getelementsbyname("psDelimSystemIDs")(0).selectedindex = 1
If ThisWorkbook.Sheets("sheet1").Range("f2").Value = "Option2" Then IE.document.getelementsbyname("psDelimSystemIDs")(0).selectedindex = 8
If ThisWorkbook.Sheets("sheet1").Range("f2").Value = "Option3" Then IE.document.getelementsbyname("psDelimSystemIDs")(0).selectedindex = 13
If ThisWorkbook.Sheets("sheet1").Range("f2").Value = "Option4" Then IE.document.getelementsbyname("psDelimSystemIDs")(0).selectedindex
= 14
If ThisWorkbook.Sheets("sheet1").Range("f2").Value = "Option5" Then IE.document.getelementsbyname("psDelimSystemIDs")(0).selectedindex = 22
If ThisWorkbook.Sheets("sheet1").Range("f2").Value = "Option6" Then IE.document.getelementsbyname("psDelimSystemIDs")(0).selectedindex
= 19
Else IE.document.getelementsbyname("psDelimSystemIDs")(0).selectedindex= 26
这是弹出链接
https://***link.com/owa.cgi/frmSelectMulti.Body?psLVMYID = 4609&psIssueID =&psOpenerLoadTS = 1531074546184&psSelectType = 1
答案 0 :(得分:1)
我不喜欢这种暗中回答:
1)您可能还需要触发关联的事件。使用您的测试HTML可能会是这样。我必须使用InternetExplorerMedium
才能从台式机上读取内容。您只需使用InternetExplorer
。
2)确保您正确指定了选项文本,例如"Option5"
不存在。上面是"...Option5 & 1"
。除非有什么我看不见/了解的东西。
Public Sub testing()
Dim ie As New InternetExplorerMedium, htmldoc As New HTMLDocument
With ie
.Visible = True
.navigate "file://C:/Users/User/Desktop/index.html" '<==You would use your URL
While .Busy Or .readyState <> 4: DoEvents: Wend
Set htmldoc = .document
Dim b As Object, testValue As String
Set b = htmldoc.getElementsByName("psDelimSystemIDs")(0)
testValue = ThisWorkbook.Sheets("Sheet1").Range("F2")
Select Case testValue '<==Use Select case syntax
Case "Option1"
b.selectedIndex = 1
Case "...Option5 & 1" '<== Ensure correct option text string
'Other cases
End Select
b.FireEvent "onchange" '<==Couldn't test this
End With
End Sub