Javascript Excel VBA单击网页中的按钮下载文件并通过电子邮件发送到电子邮件列表

Javascript Excel VBA单击网页中的按钮下载文件并通过电子邮件发送到电子邮件列表,javascript,html,excel,vba,web-scraping,Javascript,Html,Excel,Vba,Web Scraping,HTML代码如下所示。按钮显示需要单击的“在Excel中打开”。单击后,它将下载一个csv文件 <div class="analyze-view-nav-bar"><div class="analyze-view-nav-bar-left-button-container"><button title="View results" class="analyze-view-nav-button office-form-theme-button button-contr

HTML代码如下所示。按钮显示需要单击的“在Excel中打开”。单击后,它将下载一个csv文件

<div class="analyze-view-nav-bar"><div class="analyze-view-nav-bar-left-button-container"><button title="View results" class="analyze-view-nav-button office-form-theme-button button-control light-background-button"><div class="button-content">View results</div></button></div><div class="analyze-view-export-to-excel-button"><div><button title="Open in Excel" class="analyze-view-export-button-container glyph-button-control-horizontal button-control light-background-button" aria-label="Open in Excel"><div class="button-content"><i class="ms-Icon ms-Icon--ExcelLogo forms-icon-size24x24" role="presentation" aria-hidden="true"></i><span class="analyze-view-export-button-label">Open in Excel</span></div></button></div></div></div>
查看在Excel中打开的结果
这是VBA

Sub test()
Dim ie As InternetExplorer
Dim doc As HTMLDocument
Dim frm As HTMLFrameElement
Dim frms As HTMLElementCollection
Dim strSQL As String

    strSQL = "https://forms.office.com/Pages/DesignPage.aspx#Analysis=true&FormId=AY3zc5go1USqcDdJLNPiTh0SDUMn3HlMvKv7KoZTC9VUN1FIWUtSREM3RVFUQjRTWUczMlNPM09CTC4u&Token=be26006342a64df49e7dafb25915c140"

    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .navigate strSQL

        Do Until .readyState <> READYSTATE_COMPLETE: DoEvents: Loop
        'Set doc = IE.document

        ie.document.all("Open in Excel").Click



    End With
End Sub
子测试()
Dim ie作为InternetExplorer
作为HTMLDocument的Dim doc
Dim frm作为HTMLFrameElement
将frms变暗为HTMLElementCollection
作为字符串的Dim strSQL
strSQL=”https://forms.office.com/Pages/DesignPage.aspx#Analysis=true&FormId=AY3zc5go1USqcDdJLNPiTh0SDUMn3HlMvKv7KoZTC9VUN1FIWUtSREM3RVFUQjRTWUczMlNPM09CTC4u&Token=be26006342a64df49e7dafb25915c140"
设置ie=CreateObject(“InternetExplorer.Application”)
与ie
.Visible=True
.导航strSQL
直到.readyState readyState_完成:DoEvents:循环
'Set doc=IE.document
ie.document.all(“在Excel中打开”)。单击
以
端接头
您可以使用选择器(假设不在父iframe/frame中)。因此,您可以通过按钮的
title
属性值来确定按钮的目标。否则,您需要协商父iframe/frame

ie.document.querySelector("[title='Open in Excel']").click
使用适当的页面加载等待

While ie.Busy Or ie.readyState < 4: DoEvents: Wend
当ie.Busy或ie.readyState<4:DoEvents:Wend时
欢迎使用SO!请查看以及如何提供。好的,但是…问题是什么?请与我们分享,您尝试了什么,并描述问题您的代码、任何错误消息和哪一行、使用代码段工具的相关html以及理想的url。它需要登录吗?它加载网页,但不单击。它显示错误。我是现在执行此操作:当ie.Busy或ie.readyState<4:DoEvents:Wend ie.document.querySelector(“[title='Open in Excel']”)时。单击这是一个运行时错误,行为ie.document.querySelector(“[title='Open in Excel']”)。单击尝试用F8逐行遍历代码以确保页面已加载-是否仍有错误?是我做的。它不会显示错误。它会单击。不确定为什么它不会一次完成所有操作。目的是完全下载excel文件并通过电子邮件将其发送到组。这是因为尝试单击发生在元素准备就绪之前。您可以告诉我们e等待项目出现。