VBA to click button without id in a frame that runs js with on click

Cammando

New Member
Joined
Apr 9, 2018
Messages
7
Hello All,
My first post after searching for a few days for a solution.

I have an internal work web page (I know, trouble from the start...)
in which I need to click a button.

(yes, search is spelt incorrectly)

I have tried many methods but can't get a solution.
like these
Code:
 ie.Document.GetElementByName("_cmdOther()").InvokeMember ("on click")
 ie.Document.getElementByName("_cmdOther()").Click
 ie.Document.all.Item
 ie.Document.parentWindow.execScript "_cmdOther()"
 Call ie.Document.parentWindow.execScript("_cmdOther()", "JavaScript")
 ie.Document.getElementById("serch").Click
 ie.document.getElementsByName("serch")(0)

Otherwise running the js may be an option but the things i have tried so far haven't worked.

Your help would be much appreciated.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Sorry the button code dropped out
Code:
<INPUT on click=_cmdOther() type=button value="Other Criteria" name=serch>
 
Upvote 0
sorry, having trouble with the html code coming up
"<INPUT on click=_cmdOther() type=button value="Other Criteria" name=serch>"
 
Upvote 0
sorry, having trouble with the html code coming up
HTML:
INPUT on click=_cmdOther() type=button value="Other Criteria" name=serch
 
Upvote 0
You are trying to do everything in one line. Have you checked that the code is referencing the correct element? It is better to get the frame, then the button and click it in separate lines.

Try this, which requires a reference to Microsoft HTML Object Library, set via Tools -> References. There are 2 MsgBox outputs which show if you're referencing the correct frame and button.

Code:
    Dim HTMLdoc As HTMLDocument
    Dim evtClick As Object
    Dim searchButton As HTMLInputElement
    
    Set HTMLdoc = IE.document.frames("frame name").document   'or frame index number instead of frame name string
    MsgBox HTMLdoc.body.outerText
    Set evtClick = HTMLdoc.createEvent("HTMLEvents")
    evtClick.initEvent "click", True, False
    Set searchButton = HTMLdoc.getElementsByName("serch")(0)
    MsgBox searchButton.outerHTML
    searchButton.dispatchEvent evtClick
 
Upvote 0
Thanks John !!
Yes, I guess I had a false sense of success when I could click check boxes with one line.
Thank you for the help, the pop-ups are a great debug tool. I will remember that one.

Unfortunately I got this error though on the final step.
Runtime error '438':
Object doesn't support this property or method.

Are you able to give me some guidance?

Alternatively, is there a way to run the js command "on click="_cmdOther()"
Sorry I am just bashing away at this from a low base.

Cam
 
Last edited:
Upvote 0
Could it being in a form cause this?
[TABLE="width: 885"]
<tbody>[TR]
[TD]
<input name="SID__" type="hidden" value="FM1022H"> [TABLE="width: 885"]
<tbody>[TR]
[TD]FORM name=f2>INPUT type=hidden value=Wd3kd7 name=WID__> INPUT type=hidden value=FM1022H name=SID__> INPUT type=hidden name=BTN_CMD>
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
Success!! Thank you so much John.

I changed the last line of code slightly to this
Code:
searchButton.Click
It didn't need the event creation.. maybe you can tell me why??

In Addition I tried duplicating the method on the next web page and when I set the HTMLdoc I get errors.
But if I set through no problem!! - I will search for a resolution, but if you have any ideas, please let me know.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,609
Members
452,660
Latest member
Zatman

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