首页 > 解决方案 > 在 IE 宏中导航网页后保存文件

问题描述

您好我正在尝试自动化我的报告自动化的下载部分。我能够通过导航获取原始数据,但我现在只能下载它,因为我的 IE 是旧版本。弹出“打开”、“保存”、“取消”。我无法发布该网站,因为它是一个客户端网络工具。

评论部分是我迄今为止尝试过的。

Sub Get_RawFile()
'
'
'
    Dim IE As New InternetExplorer
    Dim HTMLDoc As HTMLDocument
    Dim HTMLselect As HTMLSelectElement
    'Dim saveInFolder As String, saveAsFilename As String
    'saveInFolder = "C:"
    'saveAsFilename = "test_" & Format(Sheets("Attendance").Range("X6").Value, "yyyymmdd")

    With IE
        .Visible = True
        .Navigate ("---------------------")

    While IE.Busy Or IE.readyState <> 4: DoEvents: Wend

    Set HTMLDoc = IE.document
    HTMLDoc.all.UserName.Value = Sheets("Data Dump").Range("A1").Value
    HTMLDoc.all.Password.Value = Sheets("Data Dump").Range("B1").Value
    HTMLDoc.getElementById("login-btn").Click

    While IE.Busy Or IE.readyState <> 4: DoEvents: Wend
    Application.Wait (Now + TimeValue("0:00:05"))

    Set objButton = HTMLDoc.getElementById("s2id_ddlReportType")
    Set HTMLselect = HTMLDoc.getElementById("ddlReportType")
    objButton.Focus
    HTMLselect.Value = "2"

    Set HTMLselectZone = HTMLDoc.getElementById("ddlTimezone")
    HTMLselectZone.Value = "PST8PDT"

    Set subgroups = HTMLDoc.getElementById("s2id_ddlSubgroups")
    subgroups.Click
    Set subgroups2 = HTMLDoc.getElementById("ddlSubgroups")
    subgroups2.Value = "1456_17"

    HTMLDoc.getElementById("dtStartDate").Value = Format(Sheets("Attendance").Range("B6").Value, "yyyy-mm-dd")
    HTMLDoc.getElementById("dtEndDate").Value = Format(Sheets("Attendance").Range("X6").Value, "yyyy-mm-dd")

    HTMLDoc.getElementById("btnGetReport").Focus
    HTMLDoc.getElementById("btnGetReport").Click
    Application.Wait (Now + TimeValue("0:00:10"))

    HTMLDoc.getElementById("btnDowloadReport").Click 'Download report button

    'saveInFolder, saveAsFilename

    End With
End Sub

标签: excelvbainternet-explorer

解决方案


推荐阅读