Command button to go to a Web page - Plus a little more :)

TylerTand

Registered User.
Local time
Today, 04:58
Joined
Aug 31, 2007
Messages
95
I know how to use:
application.hyperlink "www.juno.com"

but what I am having trouble with is getting the focus on the webpage so that I can maneuver to the MemberID and send my name and password on through code.

I have tried to use send keys but for some reason it can get to the member ID field but then doesn't put in the actual letters

Any help would greatly be appreciated.

Tyler
 
You'll need to use the IE object. Here's a sample:

Code:
    Dim oIE As InternetExplorer
    
    Set oIE = New InternetExplorer
    
    With oIE
        .Visible = True
        .Navigate "http://www.juno.com"
        Do Until .ReadyState = READYSTATE_COMPLETE
            DoEvents
        Loop
        
        'Automatically log in
        .Document.All("[COLOR="Red"]txtUserName[/COLOR]").InnerText = Me.txtUserName
        .Document.All("[COLOR="Red"]txtPassword[/COLOR]").InnerText = Me.txtPassword
        .Document.All("[COLOR="Red"]btnSignIn[/COLOR]").Click
        
        Do Until .ReadyState = READYSTATE_COMPLETE
            DoEvents
        Loop
    End With

The trick here is to replace the three above words in red with the names of the controls on the webpage you are trying to log on to. You get this by viewing the source of the page you are trying to log on to and getting the field names that way. Just search the source for the words around your login name ("Email:" or "Password:", for example) and you should be able to discern the names of the controls that are relevant to you.

The variables Me.txtUserName and Me.txtPassword should be replaced with your own variable names for those fields.

EDIT:

I forgot to give you the constant values for the ReadyState property of the IE object. Here they are. You'll need to set these up as constants or use the numbers themselves.


Code:
Const READYSTATE_UNINITIALIZED=0 'Never used, except as default initialization state
Const READYSTATE_LOADING=1 'Control is loading its properties
Const READYSTATE_LOADED=2 'Control has been initialized 
Const READYSTATE_INTERACTIVE=3 'Control is interactive but not all data is available
Const READYSTATE_COMPLETE=4 'Control has all its data
 
Last edited:

Users who are viewing this thread

Back
Top Bottom