VBA Into IE Automation problem

supdawg

Well-known Member
Joined
Mar 18, 2007
Messages
608
For the past two days, I have been working hard trying to figure out how to automate an internal site here at work so we can process bulk items via excel on an internal site.

I have made some progress today, but now I am totally stuck. I have been reading eveything I can on htmldocument, but my head is spinning. :eek:

The website is a very simple website.

You take an input, click a button. This will them create a small HTML table with a text input box and another button.

Code:
Sub VisitWebsite()
Dim ie As Object
Dim tcode As String
Dim sURL As String
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
sURL = [URL="http://sample.jsp/"]http://sample.jsp[/URL]
ie.navigate sURL
ie.Visible = True
tcode = "apples"
 
While ie.busy
DoEvents
Wend
Application.Wait Now() + TimeValue("00:00:03")
 
For Each ieForm In ie.document.forms
    ieForm(1).Value = tcode
    ieForm.submit
    Set ieForm = Nothing
    Exit For
Next

The code ieForm(1).Value = tcode works. The code ieForm.submit also hits submit on the button.

The problem is I cannnot figure out how to access the 2nd button which is generated when you click the 1st button. I have tried every variation of ieForm(1).Value. There appears to be only 3 forms (0, 1, 2). When I try 3 or greater, I get an error.

When I use ieForm(2).Value = "something", the Retrieve button text actually changes name to "something".

I've attached a screen shot of the webpage. I can insert text into the top Track Code box, and click Retrieve.

I can't change the text in the Routing Position field, and I cannot click the "Set" button. Any help would be greatly appreciated. :biggrin: I am still a beginner with VBA and it took me a while just to get it to work with the 1st input box.

49988242.png
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I don't know much about this but try to get the name of that Input Button from HTML source code and click through code:

Code:
ie.Document.getElementById("Default").Click
' Default is the Input Button name in HTML code.

And I have a qus...

Why "Exit For" is there in your for loop..?

Code:
For Each ieForm In ie.document.forms
    ieForm(1).Value = tcode
    ieForm.submit
    Set ieForm = Nothing
    Exit For
Next

Because of Exit for, in any condition this loop will execute one time only..
 
Last edited:
Upvote 0
The Exit For is in there because I only want to press the one button. I have tried to loop through all of them, but there is only 1 of them I can use. To be honest with you I don't know how to get the ieForm to an object without this For Each loop.

I'll try the

ie.Document.getElementById("Default").Click
</pre>
 
Upvote 0
What's the Excel connection?

It is possible to automate a browser like IE using VBA but it's almost impossible to help with that without more information.:)
 
Upvote 0
Norie, the goal of this program will be the end user will be able to take a list of items in excel and the tool will loop through those items and utilize this code to update their status in a website.

It's something the team at work currently does one at a time, and sometimes will have to do this for a hundred or so items. Since almost all of the data we get at work comes natively in Excel, it will be easy to simply drop the list into the tool and click a process button.

I've already said this site is an internal site at my work. I've provided a screen shot of what the site looks like. I've also explained that I can input a variable into the top input box and click the Retrieve button, but I cannot access the secondary input box, nor can I click the secondary button as well. I've also provided my code that does work right now to get me where I am stuck. I'm not sure what else information I can provide to help you help me?
 
Upvote 0
I don't know much about this but try to get the name of that Input Button from HTML source code and click through code:

Code:
ie.Document.getElementById("Default").Click
' Default is the Input Button name in HTML code.
And I have a qus...

Why "Exit For" is there in your for loop..?

Code:
For Each ieForm In ie.document.forms
    ieForm(1).Value = tcode
    ieForm.submit
    Set ieForm = Nothing
    Exit For
Next
Because of Exit for, in any condition this loop will execute one time only..

I tried to use ie.Document.getElementById("Default").Click and it gave me run time error.

Any other ideas? I am completely stumped.
 
Upvote 0
Here is something which I have done successfully:

Code:
Dim ie As InternetExplorer

Sub ExtractData()
    
    Application.ScreenUpdating = False
    
    Set ie = New InternetExplorer
    
    On Error Resume Next
    
    ie.Navigate "https://www.google.com/accounts/Login?hl=en&continue=http://www.google.co.in/"
    
    ie.Visible = True
    
    'Loop unitl ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop
    Do Until ie.Document.ReadyState = "complete"
        DoEvents
    Loop
    
    
    ' Login id for google
    ie.Document.all.Item("Email").Value = "abc@abc.com"
    
    ' Login password for google
    ie.Document.all.Item("Passwd").Value = "password"
    
    ' Click on sign in
    ie.Document.getElementById("signIn").Click
        
    
    'Loop unitl ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop
    Do Until ie.Document.ReadyState = "complete"
        DoEvents
    Loop
               
    'ie.Quit
    
End Sub
 
Upvote 0
I was able to find out the name of one of the elements. It's the input box above (Routing Position).

ie.document.getElementById("routePosition").Value

Now, I just can't click the "Set" button now. I think I've found the name of it "action", but I can't seem to click it. It appears to do nothing?

So close now!!!! just one more button
 
Upvote 0
Would it helped if I posted the HTML code?

I just want to click the final "Set" button in my attached image and I will be done!
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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