首页 > 解决方案 > 在 URL 中使用 VBA 激活 Onchange 功能

问题描述

我必须使用 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

标签: excelvbavisibilityonchange

解决方案


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

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

推荐阅读