首页 > 解决方案 > 从 url 的下拉列表中选择一个选项

问题描述

我正在尝试使用 vba 函数 getElementById 选择下拉列表的第一个选项,但由于出现运行时错误而无法继续进行。以下是我通过互联网找到并对其进行了一些更改的代码。

    Dim IE As Object
    Dim oHtml As HTMLDocument
    Dim oElement As HTMLUListElement
    Dim dados As HTMLSelectElement
    Dim i As Integer
    Dim x As String

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False          ' Keep this hidden.

    IE.Navigate sSiteName



Set oHtml = New HTMLDocument

Set dados = oHtml.getElementById("ReportViewerControl_ctl04_ctl03_txtValue")
dados.Focus
dados.selectedIndex = 1
dados.FireEvent "onchange"

这是 HTML 代码截图: 在此处输入图像描述

标签: htmlexcelvba

解决方案


推荐阅读