【问题标题】:Cannot press button with VBA无法使用 VBA 按下按钮
【发布时间】:2015-01-07 02:54:49
【问题描述】:

我想使用 Internet Explorer 通过 VBA 在网页上按下按钮。 我对几个网页都这样做没有问题,但我不能对一个特定的网页这样做。

按钮的HTML代码是

<button type="submit" name="submitImportFile" id="submitImportFile" class="btn btn-default pull-right" >
<i class="process-icon-next"></i>
<span>Pasul următor</span>
</button>

如何使用 VBA 按下它?

我试过了

Set allhyperlinks = IE.Document.getelementsbytagname("button")
        For Each hyper_link In allhyperlinks
            If hyper_link.getattribute("name") = "submitImportFile" Then
                hyper_link.Click
                Exit For
            End If
        Next

...它不工作。 谢谢!

我发现当从另一台计算机上运行时,代码运行良好。 但是当我从桌面运行它时,我在行中收到错误“需要对象”

ie.Document.getElementById("import").Click

为什么会出错?我检查了 VBA 引用,它们在两台计算机上都是相同的。

【问题讨论】:

    标签: vba button webpage


    【解决方案1】:

    您不需要.GetAttribute 电话。

    For Each hyper_link In allhyperlinks
          If hyper_link.Name = "submitImportFile" Then
               hyper_link.Click
               Exit For
          End If
    Next hyper_link
    

    这应该足以检查元素的.Name。请记住,默认情况下 VBA 区分大小写。您不使用以下内容是否有原因?

    IE.Document.getElementById("submitImportFile").Click

    【讨论】:

    • 昨天您的解决方案有效,今天它不再有效。我只是不明白。按下按钮,但页面保持不变。如果我用鼠标按下按钮,那么它可以工作!
    • 我无法真正说明为什么按钮没有处理呼叫但它似乎正在点击。就我个人而言,我避免使用&lt;button&gt;.Click 方法,而倾向于使用类似IE.Document.getelementsbytagname("form")(0).submit 的方法。
    猜你喜欢
    • 2016-03-26
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    相关资源
    最近更新 更多