Hello descart
There can be two approaches to execute a chain of table functions in Excel:
1) Write a new table-valued function in C#/.NET (or in VB.NET) which calls all the table functions sequentially, as explained here:
How to Add a New Table Function to Excel2) Write an Excel Macro in VBA to call the table functions in sequence.
Following example shows, how you can call a table function in VBA macro:
C# code in Excel add-in:- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("Finaquant_ExcelTable")]
public class ExcelTable
{
...
public void GetPriceTable(string xCostTblName, string xMarginTblName,
string xMetaTblName = null, string WorkbookFullName = null,
string xPriceTblName = "Price", string TargetSheetName = "PriceTable",
string inKeyFig1 = "costs", string inKeyFig2 = "margin",
string outKeyFig = "price", double StdMargin = 0.25,
string CellStr = "A1", bool ClearSheetContent = true)
public void GetPriceTable_macro()
- GeSHi ©
...
Calling Table Functions in Excel VBA (macro): - Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
' Calling GetPriceTable in Excel VBA
Sub Test_GetPriceTable()
Dim ExcelTbl
As Object:
Set ExcelTbl
= CreateObject("Finaquant_ExcelTable") ' Call .NET method with parameters
Call ExcelTbl.GetPriceTable("Cost", "Margin1")
' Call .NET method without parameters (macro)
Call ExcelTbl.GetPriceTable_macro
End Sub
- GeSHi ©
In my opinion, writing a higher-level new table function in .NET is the simpler and better solution.
The names of the input tables (ListObject in Excel) can either be hardwired in the code, or they can be read from some Excel cells, or they can be entered in user forms as explained above.
Tunc