Excel VBA-访问网站,生成报告并生成在IE对话框栏上按“保存" [英] Excel VBA - Access Website, generate report & press save on IE dialog bar

查看:91
本文介绍了Excel VBA-访问网站,生成报告并生成在IE对话框栏上按“保存"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对一个在其他主题和论坛中已经讨论过的主题有疑问,但我无法使其适合我.所以我来这里问有关我个人代码的问题.

I have a question regarding a topic that is already discussed in some other threads and forums but I do not manage to make it work for me. So I came here to ask that questions concerning my individual code.

基本上,我访问Intranet站点,并根据一些输入(通过复选框)使用SAP的数据创建报告.

Basically, I access an intranet-site and based on some input (via checkboxes) a report is created with data from SAP.

生成报告并IE提示我按下其对话框上的保存"按钮后,出现了我的问题.我没有设法使那部分自动化.

My problem arises after the report is generated and IE prompts me to press the "save" button on its dialog box. I do not manage to automate that part.

您能帮我吗?我想将报告存储在下载"文件夹中.

Could you help me here? I would like to store the report in the "Downloads" Folder.

您将在下面找到我的代码.由于合规性原因,我无法显示原始URL.

You'll find my code below. Due to compliance reasons I cannot show the original URL.

任何帮助都广受赞赏.

最佳西蒙


Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim i As Integer

Set ie = New InternetExplorerMedium
ie.Visible = True
ie.navigate "https://blablablablablabla"
Application.Wait (Now + TimeValue("00:00:03"))

Set html = ie.document

html.getElementById("ctl00_MainContent_RadCboRepFilter1_Arrow").Click
Application.Wait (Now + TimeValue("00:00:01"))

html.getElementsByClassName("rcbList")(0).Children(5).Click
Application.Wait (Now + TimeValue("00:00:01"))

html.getElementById("ctl00_MainContent_RadCboRepFilter2_Arrow").Click
Application.Wait (Now + TimeValue("00:00:01"))

html.getElementsByClassName("rcbList")(0).Children(0).Click
Application.Wait (Now + TimeValue("00:00:01"))

html.getElementById("ctl00_MainContent_RadCboListOppStatus_ctl01").Click

html.getElementById("ctl00_MainContent_RadCboListOppStatus_ctl02").Click

html.getElementById("ctl00_MainContent_RadcboListSalesStage_ctl00").Click

html.getElementById("ctl00_MainContent_RadcboListSalesStage_ctl01").Click

html.getElementById("ctl00_MainContent_RadcboListSalesStage_ctl02").Click
Application.Wait (Now + TimeValue("00:00:01"))

html.getElementById("MainContent_BtnRunReport").Click

End Sub

推荐答案

通常,从IE浏览器下载文件时,它将显示提示,让用户单击保存"按钮.我们可以使用Application.SendKeys%{s}"命令在VBA中单击保存"按钮.

Generally, When download file from IE browser, it will display a prompt to let user click the Save button. we could use the Application.SendKeys "%{s}" command to click the Save button in VBA.

示例代码如下:

Sub Test()
    Dim IE As Object

    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Visible = True
        .Navigate "<the website url>"

        While IE.ReadyState <> 4
            DoEvents
        Wend

        'click the button to download the file.
        IE.Document.getElementbyId("btnDowloadReport").Click

        'wait the download prompt appear
        Application.Wait (Now + TimeValue("00:00:03"))

        Application.SendKeys "%{s}"

        'Waiting for the site to load.
    End With
    Set IE = Nothing
End Sub

HTML页面资源:

<a id="btnDowloadReport" href="https://research.google.com/pubs/archive/44678.pdf" download>Download</a>

[注意]请检查您的IE浏览器设置,确保下载路径为下载"文件夹.

[Note] Please check your IE browser setting, make sure the Download path is the "Downloads" Folder.

这篇关于Excel VBA-访问网站,生成报告并生成在IE对话框栏上按“保存"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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