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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1759398272, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Power-Query/M-formula/examples/Hello-world(84): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78