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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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