Enter password

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Enter password

Post by Don Wells »

    I'm running Excel 2003 and Firefox 24.0
    I have a VBA project which follows a hyperlink from an Excel spreadsheet to a web page with a password entry form. On opening the web page, the cursor is positioned in the password field awaiting my input. Can I have my VBA code wait for the page to complete its opening process and then enter the password automatically?
    Any guidance will be greatly appreciated.
Regards
Don

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Enter password

Post by HansV »

Can you provide the password as an argument in the URL? If so, you can use the ExtraInfo argument of the FollowHyperlink method to specify it, e.g.

ActiveWorkbook.FollowHyperlink Address:="http://www.somewebsite.com", ExtraInfo:="mypassword"

or

ActiveWorkbook.FollowHyperlink Address:="http://www.somewebsite.com", ExtraInfo:="password=mypassword"

The exact syntax depends on the web page.
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Enter password

Post by Don Wells »

Thanks for the response Hans. However neither syntax seems to work.

I have been successful with the following SendKeys approach but don't like the forced wait time. Is there some way to detect that the page has finished loading?

Code: Select all

Public Sub test()

  returnvalue = Shell("C:\Program Files (x86)\Mozilla Firefox\firefox.exe rogers.com", 1)
  newHour = Hour(Now())
  newMinute = Minute(Now())
  newSecond = Second(Now()) + 10
  waitTime = TimeSerial(newHour, newMinute, newSecond)
  Application.Wait waitTime
  SendKeys "password~" ', True
  
End Sub
T.I.A.
Regards
Don

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Enter password

Post by Rudi »

Found these two code samples...
I have no idea if it will do the job, but worth a try on both.

Code: Select all

Sub Test()
    Set ie = CreateObject("InternetExplorer.application")
    ie.Visible = True
    ie.Navigate ("http://enter web page here")
    Do
        If ie.ReadyState = 4 Then
            ie.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
    ie.Document.Forms(0).all("User").Value = "me"
    ie.Document.Forms(0).all("Password").Value = "mypasssword"
    ie.Document.Forms(0).submit
    
End Sub

Sub internetlogon()
   With CreateObject("InternetExplorer.Application")
     .Navigate "http://enter web page here"
     Do until .ReadyState = 4
       DoEvents
     Loop
     DoEvents
     With .document
        .items("username")="<yourname>"
        .items("usernamesend").submit
     End With
  End With
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.