VBA在网页“包含验证功能”中单击Onclick按钮

时间:2018-12-02 09:54:39

标签: excel vba excel-vba

正在为“自动化IE”项目工作的Iam需要帮助。

我正在尝试通过将“开始日期”和“结束日期”作为输入来假脱机从网站获取一份excel报告,iam可以使用我的代码提供输入日期,但是iam无法单击“生成”按钮。.

以下是从&到日期的HTML源代码

<input name="ctl00$ContentPlaceHolder1$txt_0" type="text" maxlength="10" id="txt_0" tabindex="1" class="watermarked" width="200px" selectionstart="txt_0" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">

<input name="ctl00$ContentPlaceHolder1$txt_1" type="text" maxlength="10" id="txt_1" tabindex="2" class="watermarked" width="200px" selectionstart="txt_1" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">

以下是“导出报告”按钮的HTML源代码

<input type="submit" name="ctl00$ContentPlaceHolder1$btnExportXLS" value="Export Report" onclick="if(!Validate()) return false;" id="btnExportXLS" tabindex="3" class="button blue" onmousedown="return isTxtwithfocus(event, this)" style="width:101px;float: none; margin-top: 2px;">

这是功能代码

function ValidateForm(src) { 
assignvalue() 
var src1 = document.getElementById("txt" + src); 

if (src1.value != '') { 

if (isDate2(src1.value, "txt_" + src) == false) { 
return false 
} 
return true } 
}

这是我的VBA代码-单击导出按钮的最后两行

Sub User_Wise_Productivity()

Dim From_Date As String
Dim To_Date As String


From_Date = InputBox("Enter report From date in (Ex: DD.MM.yyy)format")
To_Date = InputBox("Enter report To date in (Ex: DD.MM.yyy)format")


Set browser = CreateObject("internetexplorer.application")
browser.Visible = True
browser.navigate ("My URL")


Do
DoEvents
Loop Until browser.readyState = 4


browser.document.getElementById("txtUserName").Value = "Myid"
browser.document.getElementById("txtPassword").Value = “Mypsw”

browser.document.getElementById("selFund").selectedIndex = "21"
browser.document.getElementById("btnSubmit").Click

Do
DoEvents
Loop Until browser.readyState <> 4




browser.navigate ("MY URL Page2")

Do
DoEvents
Loop Until browser.readyState <> 4


Dim reprt As String
reprt = "11"


    With browser
        Set Post = .document.getElementById("ddlrptlist")
       For Each elem In Post.getElementsByTagName("option")
            If elem.Value = reprt Then elem.Selected = True: Exit For
        Next elem

  .document.getElementById("ddlrptlist").FireEvent ("onchange")

    End With

Do
DoEvents
Loop Until browser.readyState <> 4

browser.document.getElementById("txt_0").Value = From_Date
browser.document.getElementById("txt_1").Value = To_Date

Application.Wait (Now + TimeValue("0:00:02"))

browser.document.getElementById("btnExportXLS").Focus
browser.document.getElementById("btnExportXLS").Click


End Sub

任何帮助,我们将不胜感激。预先感谢。

0 个答案:

没有答案