Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA:Excel宏代码更正_Vba_Excel - Fatal编程技术网

VBA:Excel宏代码更正

VBA:Excel宏代码更正,vba,excel,Vba,Excel,我正在寻找一个VBA代码,可以帮助我点击一个网页按钮。我得到了下面的VBA从一个网站的工程,如预期的 Sub followWebsiteLink() Dim ie As InternetExplorer Dim html As HTMLDocument Dim Link As Object Dim ElementCol As Object Application.ScreenUpdating = False Set ie = New InternetExplorer ie.Visible

我正在寻找一个VBA代码,可以帮助我点击一个网页按钮。我得到了下面的VBA从一个网站的工程,如预期的

Sub followWebsiteLink()

Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim Link As Object
Dim ElementCol As Object

Application.ScreenUpdating = False

Set ie = New InternetExplorer
ie.Visible = True

ie.navigate "https://www.google.co.in"

Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Loading website…"
DoEvents
Loop

Set html = ie.document
Set ElementCol = html.getElementsByTagName("a")

For Each Link In ElementCol
If Link.innerHTML = "Google Pixel 2" _ 'Or u can use "Advertising"
Then
Link.Click
End If
Next Link

Set ie = Nothing
Application.StatusBar = ""
Application.ScreenUpdating = True
End Sub

请尝试此代码,为我点击
登录

代码 编辑 您可以使用此代码获取href:

For Each Element In buttonclick
Debug.Print Element.href
Next
或获取内部文本:

For Each Element In buttonclick
Debug.Print Element.innerText & " " & i
i = i + 1
Next
'Where i is the number of the item
然后可以使用条件语句,例如:

For Each Element In buttonclick
If Element.href = "href_link" Then Element.Click
Next


谢谢@danieltakeshi,请指导我如何在代码中提及HREF,这样我就不会点击错误的链接/按钮。。。事实上,现在这将把我带到一个单独的页面,因为类名(“_2k0gmP”)不是唯一的值,还有其他具有相同值的标记……是的,buttonclick(0)在Flipkart上出售,buttonclick(1)是广告,buttonclick(2)是礼品卡,[…],buttonclick(7)是登录。@danieltakeshi
buttonclick(7)。单击
works,我真的很期待看到我们如何适应HREF“/account/login?ret=/”或HTML值“登录”到这个。。。。为了安全起见。。。。将来网站上的任何更改都可能导致我点击错误的按钮:)我希望你能理解我!这将是我的最后一个问题。。。。如果我问的问题太多,我很抱歉。。。。如果这不可能,请让我知道:(谢谢@danieltakeshi
For Each Element In buttonclick
Debug.Print Element.innerText & " " & i
i = i + 1
Next
'Where i is the number of the item
For Each Element In buttonclick
If Element.href = "href_link" Then Element.Click
Next
For Each Element In buttonclick
If Element.innerText = "Log In" Then Element.Click
Next