在网站的日期字段中输入日期,然后单击查看报告按钮

时间:2019-06-29 00:12:27

标签: html excel vba

我曾经使用过VBA,但从未使用它来抓取网站,所以我是新手。 我正在尝试使用VBA下班到我的SSRS网站,输入报告的日期并运行它。我已经尽力编写了代码,但是它一直在给我

  

运行错误时间91:未设置对象变量或带块变量。

下面是我的代码

Sub AgingReport()    
    Dim IE As New SHDocVw.InternetExplorerMedium
    Dim HTMLDoc As MSHTML.HTMLDocument
    Dim ReportDate As MSHTML.IHTMLElement

     IE.navigate "www.example.com"
        IE.navigate 
        IE.Visible = True
      Application.Wait Now + #12:00:04 AM#

    Do While IE.readyState <> READYSTATE_COMPLETE
    Loop

    Set HTMLDoc = IE.document

    Set ReportDate = HTMLDoc.getElementById("ReportViewerControl_ctl04_ctl09_txtValue")
        ReportDate.Value = "06/28/2019"

    HTMLDoc.getElementById("ReportViewerControl_ctl04_ctl00").Click     
End Sub

下面是HTML。请让我知道如何批准该代码。

HTML用于日期字段

<input name="ReportViewerControl$ctl04$ctl09$txtValue" class="null" 
id="ReportViewerControl_ctl04_ctl09_txtValue" onkeypress="if 
(WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'ReportViewerControl$ctl04$ctl09$txtValue\',\'\')', 0)" type="text" size="28">

以下是该按钮的HTML,该按钮已作为输入代码

<input name="ReportViewerControl$ctl04$ctl00" id="ReportViewerControl_ctl04_ctl00" type="submit" value="View Report">

1 个答案:

答案 0 :(得分:0)

我更改了一些代码,并添加了一个HTML按钮元素

希望有帮助!

Sub AgingReport()

Dim IE As New SHDocVw.InternetExplorerMedium
Dim HTMLDoc As MSHTML.HTMLDocument
Dim ReportDate As MSHTML.IHTMLElement
Dim HtmlButton As MSHTML.IHTMLElement

 IE.navigate "www.example.com"
    IE.navigate 
    IE.Visible = True
  Application.Wait Now + #12:00:04 AM#

Do While IE.readyState <> READYSTATE_COMPLETE
Loop

Set HTMLDoc = IE.document

Set ReportDate = HTMLDoc.getElementById("ReportViewerControl_ctl04_ctl09_txtValue")
    ReportDate.Value = "06/28/2019"

Set HtmlButton = HTMLDoc.getElementById("ReportViewerControl_ctl04_ctl00")
HtmlButton.Click

End Sub
相关问题