Consulting

Results 1 to 3 of 3

Thread: Hit button and download file using excel vba on web page

  1. #1

    Hit button and download file using excel vba on web page

    I have below code which opens web page, calls JavaScript function but doesn't hit "OK" button. Next I want to save .csv file by calling another function.

    Code:

    Option Explicit
    Sub SaveCsv()
    Dim str1, str2, str3, str7, URL As String
    Dim ie, frm As Object
    Dim i As Long
    Dim FF As Integer
    'Dim elems As IHTMLInputTextElement
    Dim wb As WebBrowser
    Dim objElement As Object
    Dim objCollection As Object
    Dim button, goBtn As Object
    
    
    On Error Resume Next
    Application.ScreenUpdating = False
    
    
    URL = "https://webtac.industrysoftware.automation.siemens.com/webpr/webpr.php?objtype=frames&g_userid=a3rgcw&g_session_id=7302840" 'for TEST
    
    
    Set ie = CreateObject("Internetexplorer.Application")
    ie.Visible = True
    ie.Navigate URL
    
    
    Do Until ie.ReadyState = 4
    DoEvents
    Loop
    
    
    ie.Navigate ("javascript:parent.gotoSearch('advanced');")
    
    
    str1 = "31 - Jan - 2001"
    str2 = "28 - Nov - 2017"
    str3 = "NX"
    str7 = "External"
    
    
    ie.Document.getelementsbyname("openedFrom_dateText")(0).Value = str1
    ie.Document.getelementsbyname("openedTo_dateText")(0).Value = str2
    ie.Document.getelementsbyname("product_family")(0).Value = str3
    ie.Document.getelementsbyname("pr_type")(0).Value = str7
    
    
    Do
    Loop While ie.Busy
    
    
    ie.Document.all.Item
    Call ie.Document.parentWindow.execScript("onSubmitFunction()", "JavaScript")
    
    
    Do
    Loop While ie.Busy
    ' Hit OK button not working
    Set goBtn = ie.Document.getElementByvalue(" OK ")
    goBtn.Click
    
    
    Set button = ie.Document.getElementByname("ok")
    button.Click
    
    
    ie.Quit
    Set ie = Nothing
    Application.ScreenUpdating = True
    End Sub
    Html button code:
    <input type="button" name="ok" id="ok" value=" OK " onclick="onSubmitFunction()">
    Csv file save code:
    <a href="javascript:getResultDataFile('csv')">[Comma-Delimited Text (CSV)]</a>
    Last edited by SamadhanG; 11-30-2017 at 10:48 PM. Reason: Formatted code

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Yes, that's correct.

  3. #3
    I din't get you. Am I missing anything?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •