Adding Table to Append Query

de3pster

New Member
Joined
Dec 17, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi I have a code now that adds a table to power query and creates a connection within the workbook. I would like to ask, how can I add this new query to an append query that already exists?

This is the code I have now

Thank you.

VBA Code:
  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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,215,749
Messages
6,126,662
Members
449,326
Latest member
asp123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top