1

In need few help please in my VBA code:

Private Sub CommandButton1_Click()
    Dim IE As Object

    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")

    ' You can uncomment Next line To see form results
    IE.Visible = False

    ' URL to get data from
    IE.Navigate "https://www.avanza.se/aktier/om-aktien.html/5247/investor-b"

    ' Statusbar
    Application.StatusBar = "Loading, Please wait..."

    ' Wait while IE loading...
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    Application.StatusBar = "Searching for value. Please wait..."

    Dim dd As String
    dd = IE.Document.getElementsByClassName(" ")(0).innerText

    MsgBox dd

    ' Show IE
    IE.Visible = True

    ' Clean up
    Set IE = Nothing

    Application.StatusBar = ""
End Sub

I want to extract a value from a webpage which is in my case (computer 17) as mention the image by using VBA macro.

Source code

I already followed this link (Trying to extract ONE value from a webpage with VBA in Excel) and it work but in my case I have multiple class inside each other.

Thank you very much

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
vraihack
  • 31
  • 5

1 Answers1

0

This is something to get you started with the InnerText case:

Dim dd As Object
Set dd = IE.Document.getElementsByTagName("tr")
Dim obj As Object
For Each obj In dd
    Debug.Print obj.innertext
Next

Write the code above on the place of dd = IE.Document.getElementsByClassName(" ")(0).innerText and see the innertext of all tr on the site.

Vityata
  • 42,633
  • 8
  • 55
  • 100
  • thank u so much,it work but i have another question please if the site need access like user and pass (sharepoint) can i still get any information from the website in case if am using this code? – vraihack Apr 10 '18 at 10:38
  • @mictec - cool that it works. [What to do when someone answers a question.](https://stackoverflow.com/help/someone-answers) Concerning the second question, it is a good idea to ask it separately. – Vityata Apr 10 '18 at 10:40