- Sub Macro2()
- ActiveWorkbook.Queries.Add _
- Name:="TabWBS112288", _
- Formula:="let Source = Excel.CurrentWorkbook(){[Name=""TabWBS112288""]}[Content] in Source"
- Workbooks("WBS test.xlsx").Connections.Add2 _
- Name:="Query - TabWBS112288", _
- Description:="Connection to the 'TabWBS112288' query in the workbook.", _
- ConnectionString:="OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=TabWBS112288;Extended Properties=""""", _
- CommandText:="SELECT * FROM [TabWBS112288]", _
- lCmdtype:=2
- End Sub
With .NET I use the Excel interop but it seems not have the same query objects as VBA. The interop has workbookconnections and models but not queries.
I need to manipulate Excel queries using C# in Visula Studio but I do not know how to.
How can I code the example VBA in C#?

Sachin SinghRank #66 · 26.2K reputationPosted Oct 12, 2020, 5:59 AM EDT
Mageshwaran RRank #411 · 6.1K reputationPosted Oct 12, 2020, 6:58 AM EDT
Kobus Burger14 reputationPosted Oct 12, 2020, 9:38 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Oct 12, 2020, 9:48 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Oct 12, 2020, 9:51 AM EDT
alice yangRank #2,329 · 607 reputationPosted Oct 12, 2020, 4:15 PM EDT
Kobus Burger14 reputationPosted Oct 13, 2020, 5:58 AM EDT