VBA help to get live data from password protected site

jbinnerz123

New Member
Joined
Feb 4, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello I am a noob but want to learn and make it easy to display data on my spreadsheet. I'm trying to get a realtime number onto my excel spreadsheet from a website that is password protected. I have the code to open the correct webpage the number is on, but then how do I get the number to show on my spreadsheet in real time. I will post the code I use to open the site, but I do not know where to go from there to get the number.

Inspecting the number I want shows :
<td align="right" class="AccountSummary" style="color: green;>-£5,79</td>

with the -£5.79 the number i want in my spreadsheet realtime. Thank you


Sub login()


Dim i As SHDocVw.InternetExplorer
Set i = New InternetExplorer
i.Visible = True


i.navigate ("website")


Do While i.readyState <> READYSTATE_COMPLETE


Dim idox As MSHTML.HTMLDocument
Set Idoc = i.document


Idoc.all.Pass.Value = "mypassword"

Dim ele As MSHTML.IHTMLElement

Dim eles As MSHTML.IHTMLElementCollection
Set eles = Idoc.getElementsByTagName("button")


For Each ele In eles

If ele.ID = "sgnBt" Then ele.click

Next

end sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi, Welcome to Mr. Excel board.

Once you logged-in in the site, you can access required value using below:


VBA Code:
msgbox idox.getElementsByClassName("AccountSummary")(0).innerText
 
Upvote 0
Hello Thank you for your reply.

So how would I write that code into my VBA? and then how would I get the value to show up in my excel spreadsheet?

Sub login()


Dim i As SHDocVw.InternetExplorer
Set i = New InternetExplorer
i.Visible = True


i.navigate ("website")


Do While i.readyState <> READYSTATE_COMPLETE

Loop


Dim idox As MSHTML.HTMLDocument
Set Idoc = i.document


Idoc.all.Pass.Value = "password"

Dim ele As MSHTML.IHTMLElement

Dim eles As MSHTML.IHTMLElementCollection
Set eles = Idoc.getElementsByTagName("button")


For Each ele In eles

If ele.ID = "sgnBt" Then ele.Click

Next ele

MsgBox idox.getElementsByClassName("AccountSummary")(0).innerText



End Sub


thank you
 
Upvote 0
Hi, Welcome to Mr. Excel board.

Once you logged-in in the site, you can access required value using below:


VBA Code:
msgbox idox.getElementsByClassName("AccountSummary")(0).innerText
[/C
[/QUOTE]
thank you for the reply

How would I write this into the vba? would i have to do another sub function, or do i even have the initial sub login correct if i am just wanting to get the live data? How would i then get the value to show up in the spreadsheet in live time? thank you
 
Upvote 0
Hi,

Yes the code is correct. Is this showing the value in message box ?
To show value in sheet use reference of worksheet.

IF not, Do these modifications -

1. After pressing button, Stop VBA for few seconds so that page loads completely.

VBA Code:
For Each ele In eles
           If ele.ID = "sgnBt" Then ele.Click
Next ele

Application.Wait (timevalue("00:00:05"))

Worksheets("sheetname").Range("A2") = idox.getElementsByClassName("AccountSummary")(0).innerText
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top