Hi all,
What I am looking for is to be able to copy and paste data from an open web page into excel. Now the reason I am not using a web query is that I need to login to the page and navigate to the correct page before getting the data, the code I have got to do this is below, I have tried to run a web query using the querytable add function etc. after this code but it fails as the site keeps asking for login even with the IE window still open to the correct page and logged in... So any suggestions?
I have heard that there is a way to make the web query login but have tried everything that I could find with no success...
Here is the code I am using to login to the site:
Thanks for any help!
Ash.
What I am looking for is to be able to copy and paste data from an open web page into excel. Now the reason I am not using a web query is that I need to login to the page and navigate to the correct page before getting the data, the code I have got to do this is below, I have tried to run a web query using the querytable add function etc. after this code but it fails as the site keeps asking for login even with the IE window still open to the correct page and logged in... So any suggestions?
I have heard that there is a way to make the web query login but have tried everything that I could find with no success...
Here is the code I am using to login to the site:
Code:
Sub Test()
Const cURL = "https://www.sharetrading.netwealth.com.au/LoginFailed.aspx"
Const cUsername = "******"
Const cPassword = "******"
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Dim qt As QueryTable
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate cURL
'Wait for initial page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
Set doc = IE.Document
'Get the only form on the page
Set LoginForm = doc.forms(0)
'Get the User Name textbox and populate it
'< input name="ctl00$ct$UserName" type="text" maxlength="30" id="ctl00_ct_UserName" style="width:160px;" />
Set UserNameInputBox = LoginForm.elements("ctl00$LoginControl1$txtLogin")
UserNameInputBox.Value = cUsername
'Get the password textbox and populate it
'< input name="ctl00$ct$Password" type="password" maxlength="30" id="ctl00_ct_Password" style="width:160px;" />
Set PasswordInputBox = LoginForm.elements("ctl00$LoginControl1$txtPassword")
PasswordInputBox.Value = cPassword
'Get the form input button and click it
'< input type="submit" name="ctl00$ct$uxBtnLogin" value="Sign In" o n c l i c k="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ct$uxBtnLogin", "", true, "Login", "", false, false))" id="ctl00_ct_uxBtnLogin" />
Set SignInButton = LoginForm.elements("ctl00$LoginControl1$btnLogin$implementation$field")
SignInButton.Click
'Wait for the new page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
'Get the HTML document of the new page
Set doc = IE.Document
IE.Navigate "https://www.sharetrading.netwealth.com.au/Private/MarketPrices/CompanyProfile/Financials.aspx?stockCode=" & ActiveCell.Value
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
End Sub
Ash.