Queries.Add method (Excel)

Adds a new WorkbookQuery object to the Queries collection.

Syntax

expression.Add (Name, Formula, Description)

expression A variable that represents a Queries object.

Parameters

Name Required/Optional Data type Description
Name Required String The name of the query.
Formula Required String The Power Query M formula for the new query.
Description Optional Variant The description of the query.

Return value

WorkbookQuery

Example

The following example shows how to add a query to a workbook from an existing CSV file.

Dim myConnection As WorkbookConnection
Dim mFormula As String
mFormula = _
"let Source = Csv.Document(File.Contents(""C:\data.txt""),null,""#(tab)"",null,1252) in Source"
query1 = ActiveWorkbook.Queries.Add("query1", mFormula)

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.