View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_2_] Leith Ross[_2_] is offline
external usenet poster
 
Posts: 128
Default Problem using internetexplorer object to open a url

On May 21, 3:44 pm, Duncan wrote:
I am trying to open a browser window from VBA and navigate to a
password-protected area but everything I have tried fails.

The navigate method fails with a url such as "http://
", I cannot get sendkeys to work either and using
formdata also seems to fail.

Can anyone provide a code snippett that opens page and hands over the
username and password?

Many thanks!


Hello Duncan,

I wrote this macro to logon to Gmail from Internet Explorer. Add your
email and password to code where indicated.

'----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Written: January 17, 2008
'Author: Leith Ross
'Summary: Logs on to Gmail using Internat Explorer
'This code first requires setting a reference to Microsoft Internet
Controls.
'In the Object Browser the properties, methods, and events appear
under SHDocVw.

Sub LogOnToGmail()

Dim IEapp As Object
Dim Password As String
Dim UserName As String
Dim URL As String

URL = "https://www.google.com/accounts/ServiceLogin?
service=mail&passive=true&rm=false&continue=https% 3A%2F
%2Fmail.google.com%2Fmail%3Fnsr%3D1%26ui%3Dhtml%26 zy
%3Dl&ltmpl=default&ltmplcache=2&hl=en/"
UserName = "Your UserName" <----- Change
Password = "Your Password" <-----Change

Set IEapp = New InternetExplorer

' Launch Internet Explorer and go to the site
With IEapp
.Visible = True
.Navigate URL
End With

' Wait until Internet Explore finishes loading
While IEapp.Busy
DoEvents
Wend

' Inserts your Email name
IEapp.Document.all("Email").Value = UserName
' Wait till the page is loaded
While IEapp.Busy
DoEvents
Wend

' Inserts your password
IEapp.Document.all("passwd").Value = Password
' Wait till the page is loaded
While IEapp.Busy
DoEvents
Wend

' Clicks the Sign In button
IEapp.Document.all("signIn").Click
While IEapp.Busy
DoEvents 'wait until IE is done loading page.
Wend

End Sub
'----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sincerely,
Leith Ross