excel vba IE点击一个按钮 [英] excel vba IE clicking a button

查看:339
本文介绍了excel vba IE点击一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Excel和VBA,我打开了一个页面。



我想点击按钮'展开'通过vba,但我收到一个错误。



我尝试使用以下列出的两个VBA命令

  Doc.getElementsByClassName (dhl-btn-main collapse-btn-expand-all)(0)。点击
Doc.getElementsByClassName(dhl-btn-main collapse-btn-expand-all)点击

我得到的错误是
运行时错误'438':对象不支持此属性或方法。

解决方案

假设Doc是IE的参考,请尝试:

  Set ElementCol = Doc.document.getElementsByClassName(dhl-btn-main collapse-btn-expand-all)

对于每个btnInput In ElementCol
btnInput.Click
下一个btnInput






工作示例

 私有子IE_Expand()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object

'创建InternetExplorer Ob ject
设置IE = CreateObject(InternetExplorer.Application)

'IE.Visible = False

IE.Navigatehttps://dhli.dhl。 com / dhli-client / shippingair; jsessionid = q3tzTzyLcL7JkxkNQ4nv7Jtrpzk1glylCyJ7vJzT27h2xBG5zXSm!599496067?0& shippingId = 151218573& accountGroup

'等待IE加载...
尽管IE.Busy
Application.Wait DateAdd(s,1,Now)
循环

IE.Visible = True

设置ElementCol = IE.document.getElementsByClassName( dhl-btn-main collapse-btn-expand-all)

ElementCol.Item(0).Click

'清理
设置IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing

Application.StatusBar =
End Sub


Through Excel and VBA, i am opening a page.

I want to click on the button 'Expand' through vba but I am getting an error.

I tried using both VBA commands listed below

Doc.getElementsByClassName("dhl-btn-main collapse-btn-expand-all")(0).Click
Doc.getElementsByClassName("dhl-btn-main collapse-btn-expand-all").Click

The error that I get is Run time error '438': Object doesn't support this property or method.

解决方案

Assuming that "Doc" is your reference to IE try this:

 Set ElementCol = Doc.document.getElementsByClassName("dhl-btn-main collapse-btn-expand-all")

 For Each btnInput In ElementCol
    btnInput.Click
 Next btnInput


Working Example:

Private Sub IE_Expand()
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object

    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")

    'IE.Visible = False

    IE.Navigate "https://dhli.dhl.com/dhli-client/shipmentair;jsessionid=q3tzTzyLcL7JkxkNQ4nv7Jtrpzk1glylCyJ7vJzT27h2xBG5zXSm!599496067?0&shipmentId=151218573&accountGroup"

    ' Wait while IE loading...
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    IE.Visible = True

    Set ElementCol = IE.document.getElementsByClassName("dhl-btn-main collapse-btn-expand-all")

    ElementCol.Item(0).Click

    ' Clean up
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing

    Application.StatusBar = ""
End Sub

这篇关于excel vba IE点击一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆