Automating with Internet Explorer

sarahlish18

Board Regular
Joined
Feb 6, 2007
Messages
60
Hello,

I am trying to use Excel VBA to conduct a transaction automatically.So far,I managed to get all the required input in.Now,I need to click the "Submit" Button.

I was thinking of using the InternetExlorer.Document.Links(x).Title to search for the link of the "Submit" button and then use the .Navigate method to proceed to the link.

But when I wrote and ran the :

InternetExlorer.Document.Links(x).Title

i get the following mesage:

"Run Time Error 98

A property or method cannot include a reference to a private object ,either as an argument or as a return value "

Please help me figure out how to get around this error.Is there a method that I can use to retrieve the name of the link?I am not familiar with automating the elements of IE...
Thank you.
 
You don't really need to understand the IMacro code. Simply use it to identify the name of the submit button and incorporate it into your VBA macro.

If for some reason this doesn't work for you an old method I used was to identify the control within the array. First it would be something like this...

Code:
Sub FindNetControl()

On Error Resume Next
Dim IE As Object

Set IE = CreateObject("InternetExplorer.Application")

IE.navigate "http://www.yoururl.com/"

Do While IE.busy: DoEvents: Loop
Do While IE.ReadyState <> 4: DoEvents: Loop
IE.Visible = True

x = 0
For Each mitem In IE.document.all
    mitem.Value = "x"
    x = x + 1
Next

That will change the caption/text of a host of controls on the sheet to their numeric position within the array and in my experience that almost always includes the submit button. In other words instead of saying "submit" it should now show the x value on screen.

So now to use the submit link you've have another Sub, the same as the above just changing the For Each section to.

Code:
 x = 0
For Each mitem In IE.document.all
    If x = {Value discovered for the submit button} then
    mitem.Click
    Exit For
Next

Its a "dirty" method but was a quick and successful method of finding which controls were which.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Thank You ScottR,I managed to get the item number of the 'Submit' button using the 'dirty' method you proposed.

Thank You Very Much!
 
Upvote 0
I know this post is old, but thanks Scott! I was finally able to solve a couple of issues I was having from this with this find. I knew the value of my Submit button was "Submit" but I didn't know the name. I was able to modify your code to use as such and it worked great:
Code:
    For Each mitem In mainDoc.all
        If mitem.Value = "Submit" Then
            mitem.Click
        End If
    Next
 
Upvote 0

Forum statistics

Threads
1,215,501
Messages
6,125,169
Members
449,212
Latest member
kenmaldonado

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