Unable to hit button and download file using excel vba on web page

SamadhanG

New Member
Joined
Dec 1, 2017
Messages
1
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:
[/FONT][/COLOR]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 
     [COLOR=darkgreen]'Dim elems As IHTMLInputTextElement[/COLOR]
    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" [COLOR=darkgreen]'for TEST[/COLOR]
     
     
    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 
     [COLOR=darkgreen]' Hit OK button not working[/COLOR]
    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 [COLOR=#242729][FONT=Arial]

Html button code:

Code:
[/FONT][/COLOR][COLOR=#333333]<input type="button" name="ok" id="ok" value=" OK " *******="onSubmitFunction()">
[/COLOR][COLOR=#242729][FONT=Arial]

Csv file save code:

Code:
[/FONT][/COLOR][COLOR=#333333]<a href="javascript[/COLOR][COLOR=#333333]:getResultDataFile('csv')">[Comma-Delimited Text (CSV)]</a> [/COLOR]

[COLOR=#242729][FONT=Arial]
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top