Hello, I was using VBA to automatically add the table in my new sheet to power query and create a connection for it. I would like to add this query to an append query that has been already created called "Staging" in the power query. Here is my current code. Thank you so much in advance.
VBA Code:
Dim wss As Worksheet
Set wss = ActiveSheet
Dim lo As ListObject
Dim sName As String
Dim sFormula As String
Dim wq As WorkbookQuery
Dim bExists As Boolean
Set wb = ActiveWorkbook
Set lo = ActiveSheet.ListObjects(1)
sName = lo.Name
sFormula = "Excel.CurrentWorkbook(){[Name=""" & sName & """]}[Content]"
'Add query
wb.Queries.Add Name:=sName, _
Formula:="let" & Chr(13) & "" & Chr(10) & " Source = Excel.CurrentWorkbook(){[Name=""" & sName & """]}[Content]" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Source"
'Add connection
wb.Connections.Add2 Name:="Query - " & sName, _
Description:="Connection to the '" & sName & "' query in the workbook.", _
ConnectionString:="OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & sName & ";Extended Properties=""""", _
CommandText:="SELECT * FROM [" & sName & "]", _
lCmdtype:=2, _
CreateModelConnection:=False, _
ImportRelationships:=False