我正在尝试自动化我的报告,但我似乎找不到正确的代码来输入我的报告的开始和结束日期。我不能张贴的链接,因为它是一个客户端的网络工具。
我尝试过通过getElementByID设置日期,它会更改日期,但它不会提取数据(根本没有数据)。当我根本不输入任何日期代码时,它会毫不费力地提取今天的数据。
我想我需要通过它的日期选择器设置日期,以完全提取数据。我希望有人能指导我完成这个过程。
注释代码是我到目前为止已经尝试过的,附加的图片是为HTML文件。
Start End Date Date Picker Start Date
Sub Get_RawFile()
'
'
'
Dim IE As New InternetExplorer
Dim HTMLDoc As HTMLDocument
Dim HTMLselect As HTMLSelectElement
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 = "1"
Set HTMLselectZone = HTMLDoc.getElementById("ddlTimezone")
HTMLselectZone.Value = Sheets("Data Dump").Range("B9").Value
Set subgroups = HTMLDoc.getElementById("s2id_ddlSubgroups")
subgroups.Click
Set subgroups2 = HTMLDoc.getElementById("ddlSubgroups")
subgroups2.Value = "1456_17"
'HTMLDoc.getElementById("dtStartDate").Value = Sheets("Attendance").Range("B6").Value
'HTMLDoc.getElementById("dtStartDate").Click
'HTMLDoc.getElementById("dtEndDate").Value = Sheets("Attendance").Range("X6").Value
'HTMLDoc.getElementById("dtEndDate").Click
HTMLDoc.getElementById("btnGetReport").Click
Application.Wait (Now + TimeValue("0:00:10"))
HTMLDoc.getElementById("btnDowloadReport").Click
End With
End Sub
发布于 2019-07-24 17:44:24
在Excel中,日期存储为十进制值。我猜你的HTML需要一个字符串,所以试着格式化:
HTMLDoc.getElementById("dtStartDate").Value = Format(Sheets("Attendance").Range("B6").Value, "yyyy-mm-dd")
https://stackoverflow.com/questions/57179748
复制相似问题