使用VBA导航网站并修改下拉框



早上好,

我正在从事一个VBA项目,我想在其中访问内部公司,登录需要,网站并从表中提取数据。我已经成功编写了将导航到正确网站的代码,然后将下拉框值从"所有交易"更改为"运行记录"。我遇到的问题是,一旦下拉框更新,我就无法将数据刷新到表中。在网站上,在下拉字段旁边是" GO"超链接。每当我尝试使用VBA激活链接时,它都会重置下拉链接,并且不会显示所需的数据。

我能够找到一个类似的帖子,其中用户解释说,该问题与要确保的站点有关,并且需要使用.fireevent。尽管这个概念对我来说很有意义,但实施是另一个故事。我的情况和对方之间的最大区别是,当他的下拉框更改时,它将激活该活动。就我而言,有一个单独的ID,我上面提到的" GO"超链接,一旦输入下拉值,就需要激活。

下面是HTML代码的一部分,其中下拉框选项以及" GO"超链接。

<select name="classList" onchange="selectClass(this);"><option class=tblrow2 value="All" selected=selected>All Schedules</option>
                    <option value="A"  >
                        Transactions-Financial
                    </option>

                    <option value="N"  >
                        Transactions-Non-Financial
                    </option>

                    <option value="RB"  >
                        Running Balance
                    </option></select>
             <input type="hidden" name="classindx" id = "classindx" value="" />
            &nbsp;&nbsp;<a href="#" onClick="submitTransForm()">&nbsp;Go&nbsp;</a>

这是我代码的一部分,它修改了下拉框值。

'try to get form by ID
   Set frm = ie.Document.getElementByID("myFormID")
   'try to get form by name
   If frm Is Nothing Then Set frm = ie.Document.getElementsByName("facilityFeeRepayForm").Item(0)
        'Set ieButton = ie.Document.getElementById("classindx") Here I tried to treat the Go hyperlink like a button but that didn't work either.  
   If frm Is Nothing Then
   Else
      ie.Visible = True
      For Each element In frm.elements
         On Error Resume Next
         Select Case element.Name
            Case "classList": element.Value = "RB"
            ie.getElementByID("classindx").FireEvent("onClick") 'nothing happens with this code
   While ie.ReadyState <> 4: DoEvents: Wend
         End Select
      Next
   End If

我感谢您提供的任何帮助。

谢谢,约翰

而不是单击链接,请尝试以下操作:

ie.Document.parentWindow.execScript "submitTransForm()", "JavaScript"

最新更新