Selecting frame in Internet Explorer from Excel

G

Guest

I am trying to logon to a website from the Excel Macro, but cannot get it to
use the correct frame on the web page. There seems to be 2 main frames to
the webpage, the login and password one, that I'm trying to use, and then the
rest of the page.

Below is the code I am using, I got it from another thread in the discussion
group.

Sub Open_Website()
Set IExplorer = CreateObject("InternetExplorer.Application")
IExplorer.Visible = True
IExplorer.navigate "http://avotus/avotus/"
Do While IExplorer.Busy And Not IExplorer.ReadyState = 4:
Application.Wait (Now + TimeValue("0:00:02"))
DoEvents
Loop

With Selection
IExplorer.document.all("Login").Value = "sl704d"
IExplorer.document.all("Password").Value = "******"
IExplorer.document.forms(0).submit
End With
End Sub
It opens the webpage perfectly, but gives me an error at the With Selection
line. I have managed to save the HTML for just the login frame and I have
run the macro successfully against this, so I'm thinking that it's not
identifying the frames on the webpage right.

My HTML programming is very limited, so that's maybe my biggest problem.

Thank's in advance for any help.
 
J

John

Hi Deke,

I'm not very clued up on navigating in IE, but have done some interesting
digging and found the following link:

http://www.dailydoseofexcel.com/archives/2004/09/22/automating-internet-explorer/

If you're trying to target a specific frame then you might want to try
looping through the frames to check the name of the one you're after:

For x = 0 To IExplorer.Document.Frames.Length - 1
Debug.Print IExplorer.Document.Frames(x).Name
Next x

You could then target the correct frame with something like:

IExplorer.Document.Frames("fraTarget").Document......

Also, its worth stepping through your code (F8) as once you've got a
reference to the document you can explore all of the elements via the Locals
window.

Anyway, hope that helps.

Best regards

John
 
G

Guest

John,

That worked perfectly, I'm now logged into the website.

Thank you very much for your help.


Cheers...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top