Search notes:

Power Query M Formula: Hello world example

Visual Basic for Applications

This Visual Basic for Applications program tries to demonstrate the minimally required steps to use the Power Query M Formula language in Excel.
option explicit

sub helloWorld() ' {

   activeWorkbook.queries.add _
     name    := "qry",        _
     formula := """Hello world"""

   dim destTable as listObject

   dim src as string
   src = "OLEDB;"                             & _
         "Provider=Microsoft.Mashup.OleDb.1;" & _
         "Data Source=$Workbook$;"            & _
         "Location=qry"

   set destTable = activeSheet.listObjects.add( _
       sourceType  := 0           , _
       source      := src         , _
       destination := cells(2, 2) )

   with destTable.queryTable ' {

       .commandType              =  xlCmdSql
       .commandText              =  array("select * from [qry]")
       .rowNumbers               =  false
       .backgroundQuery          =  true
       .refreshStyle             =  xlInsertDeleteCells
       .saveData                 =  false
       .refreshOnFileOpen        =  true
       .adjustColumnWidth        =  true
       .refreshPeriod            =  0
       .preserveColumnInfo       =  true
       .listObject.DisplayName   = "destinationTable"

       .refresh backgroundQuery :=  false

    end with ' }

end sub ' }
Github repository about-Power-Query-Formula-M, path: /examples/Hello-world/VBA.vb
Whe executed, the program creates this list table:

Index