【问题标题】:Activate Onchange function with VBA in URL在 URL 中使用 VBA 激活 Onchange 功能
【发布时间】:2019-12-04 21:36:47
【问题描述】:

我必须使用 excel 在网站内填写表格。 该网站的工作方式是这样的 - 当从组合框中选择某些内容时,新的输入框会使用 onchange 函数激活,如下代码所示。

<select name="murat" id="murat" class="normalText" onchange="muratonChange(this);">
function muratonChange(source) {
  var muratIndex, Visibility;
  muratIndex=source.selectedIndex
  document.all.ayaz.style.visibility="visible";

我可以选择组合框中的任何内容。但是,输入框不可见,因此我无法更改它们。 使用下面的 vba 代码为组合框赋值

While .Busy Or .readyState < 4: DoEvents: Wend

        Do
            DoEvents
            On Error Resume Next
            Set ele = ie.document.querySelector("murat")
            On Error GoTo 0
            If Timer - t > MAX_WAIT_SEC Then Exit Do
        Loop While ele Is Nothing
        If Not ele Is Nothing Then
            ele.Click                            
            ie.document.getElementsByName("murat")(0).Value = Application.VLookup(Sheets("fener").Range("D3").Text, Sheets("bahce").Range("A:B"), 2, False)
        End If

【问题讨论】:

  • 你能分享网址还是登录背后的页面?您是否尝试过 parentWindow.execScript 来触发该函数或附加一个 htmlevent 以进行更改并调度它?
  • 实际上网站在登录后面,也在公司防火墙后面。我已经更改了项目的名称。顺便说一句,我没有尝试 parentWindow.execScript 来触发该功能。只是试图找到fireevent“onChange”并不能成功。

标签: excel vba visibility onchange


【解决方案1】:

首先请发表评论和帮助,而不是编辑我的英语语法来获得徽章等。 感谢用户@QHarr。我跟着他的脚步。下面的代码解决了我的问题。

        Dim CurrentWindow As HTMLWindowProxy: Set CurrentWindow = ie.document.parentWindow
        Call CurrentWindow.execScript("muratonChange(this)")

【讨论】:

    猜你喜欢
    • 2018-04-06
    • 1970-01-01
    • 2011-02-03
    • 2017-01-12
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多