Re: Using sendkeys and loop to download files
Hi,
That is good news - should make things much easier for you.
The following should help to get you started. I've used http://www.fool.co.uk/index.aspx as an example site. If you register there (it's free and just for the purposes of illustration). The following code will login, using the details provided, and navigate to a given page.
Sub GoSurf()
'Need references to Microsoft Internet Controls and Microsoft Forms Library
Dim ieApp As InternetExplorer
Dim ieDoc As HTMLDocument
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputElement
'create a new instance of ie
Set ieApp = New InternetExplorer
'you don’t need this, but it’s good for debugging
ieApp.Visible = True
'assume we’re not logged in and just go directly to the login page
ieApp.navigate "https://www.fool.co.uk/secure/members/login.aspx"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.document
'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
Set UserNameInputBox = .elements("ctl00$MainContent$ctlLogin$txtUsername")
UserNameInputBox.Value = "YourNameHere"
Set PasswordInputBox = .elements("ctl00$MainContent$ctlLogin$txtPassword")
PasswordInputBox.Value = "YourPasswordHeretestweb"
Set SignInButton = .elements("ctl00_MainContent_btnSubmit")
SignInButton.Click
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
'now that we’re in, go to the page we want
ieApp.navigate "http://www.fool.co.uk/latest-stories/"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
End Sub
Display More
It's a bit of a mish-mash of exisiting routines that I have just to serve as an illustration. The initial routine came from here : http://www.dailydoseofexcel.co…te-that-requires-a-login/ . Note that you will need to set a couple of References in the VBE.