Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
KM007
Helper II
Helper II

Translate VBA into M or DAX to create a table

Hi

 

Is it possible to translate my VBA code below into M or DAX so the table is created in Power BI?

 

Sub HL_Sectors()

    Dim XMLPage As New MSXML2.XMLHTTP60
    Dim HTMLDoc As New MSHTML.HTMLDocument
    Dim HTMLSector As MSHTML.IHTMLElement
    Dim HTMLSectorID As MSHTML.IHTMLElement
    Dim RowNum As Long, ColNum As Integer
    
    XMLPage.Open "GET", "http://www.hl.co.uk/funds", False
    XMLPage.send
    
    HTMLDoc.body.innerHTML = XMLPage.responseText
    
    Set HTMLSector = HTMLDoc.getElementById("search-sector")

    Range("A:A").ClearContents
    
        RowNum = 1
        For Each HTMLSectorID In HTMLSector.getElementsByTagName("option")

            ColNum = 1
                Cells(RowNum, ColNum) = HTMLSectorID.innerText
                ColNum = ColNum + 1

            RowNum = RowNum + 1
        Next HTMLSectorID
    
End Sub

Thanks

2 REPLIES 2
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @KM007,

 

As we're not very familiar with VBA, could you be more precisely with what you are trying to extract from that page? For most web pages, you should be able to use the Web connector in Power BI Desktop to extract data as mentioned by @Greg_Deckler above. Smiley Happy

 

Regards

Greg_Deckler
Community Champion
Community Champion

What is the information that you are trying to extract from that page? You would use the Get Data -> Web option and then you're going to just have to drill through the DOM until you find the right section.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors