Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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
Excel VBA:转到IE站点并按元素勾选_Excel_Vba_Internet Explorer - Fatal编程技术网

Excel VBA:转到IE站点并按元素勾选

Excel VBA:转到IE站点并按元素勾选,excel,vba,internet-explorer,Excel,Vba,Internet Explorer,使用IE导航的新手。我正在尝试访问网站https://www.thetrainline.com/并通过使用elementgetElementsByID(“Return”).FirstChild勾选Return按钮。单击,但这只会打开站点。它不勾选返回选项 有什么想法吗 Public Function GetHTML() As String On Error GoTo ErrorEscape Dim URL As String Dim IE As Object: Set

使用IE导航的新手。我正在尝试访问网站
https://www.thetrainline.com/
并通过使用element
getElementsByID(“Return”).FirstChild勾选
Return
按钮。单击
,但这只会打开站点。它不勾选返回选项

有什么想法吗

Public Function GetHTML() As String

    On Error GoTo ErrorEscape

    Dim URL As String
    Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
    Dim HTML As Object
    Dim myElement As Object

    'Define URL
    URL = "https://www.thetrainline.com/"

    IE.navigate URL
    Application.Wait (Now + TimeValue("0:00:03"))
    MsgBox ("IE Loaded")

    Set myElement = IE.getElementsByID("return").FirstChild.Click

    Exit Function

ErrorEscape:
    Set IE = Nothing
    Set HTML = Nothing

End Function

另外,我希望很多用户能够在不下载任何东西的情况下使用它。因此,我为什么不使用Selenium。

我尝试修改您的代码,单击“返回”单选按钮

修改代码:

Sub demo()
 Dim URL As String
    Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
    Dim HTML As Object
    Dim myElement As Object

    'Define URL
    URL = "https://www.thetrainline.com/"
IE.Visible = True
    IE.navigate URL
    Application.Wait (Now + TimeValue("0:00:03"))
    'MsgBox ("IE Loaded")

    IE.document.getElementById("return").Click

ErrorEscape:
    Set IE = Nothing
    Set HTML = Nothing

End Sub
输出:


也许您在
Set myElement=
行上遇到了错误?我认为,
单击
不会返回任何内容。使用超时来检测站点是否“加载”不是执行此操作的方法。IE有事件告诉你一个页面真的被加载了。第二个getElementById是一个依赖于文档的函数。所以,在你启动这个之前,先拿到文件。谢谢你们两个,@ThomasLudewig。所以如果我没有文件。但我只想简单地点击框并选择它?Maybee您将看到acc.Javascript函数;)如果使用document.getElementById函数获取元素,现在可以执行.click()。你在IE.getElement>>>中也有一个输入错误。这个网站上有很多示例。看一看。