Skip to content Skip to sidebar Skip to footer

How To Read Html Code In Order To Grab Data With Excel Vba

I'm trying to grab som data from a webpage with Excel VBA. The HTML code is:

Solution 1:

I would say you have 2 options:

1. DOM

.document.getElementById("skuPriceLabel").getElementsByTagName("span")(1).getEl‌​ementsByTagName("span")(0).innerText

2. Regex

Use regex: content=""NOK"">(.*?)< with this function

Public Function GetRegex(str As String, reg As String, Optional index As Integer) As String
    On Error Resume Next
    Set regex = CreateObject("VBScript.RegExp")
    regex.Pattern = reg
    regex.Global = True
    If index < 0 Then index = 0
    If regex.test(str) Then
        Set matches = regex.Execute(str)
        GetRegex = matches(index).SubMatches(0)
        Exit Function
    End If
    GetRegex = ""
End Function

Post a Comment for "How To Read Html Code In Order To Grab Data With Excel Vba"