Yes, it is possible in C#, VB.NET and some others as well. The below is for C# to reference your question -
You can pick up on all of the basics as a starting point at -
How to access Office interop objects | Tutorial[
^]
Some code to point you in the right direction, you need to reference the 'Microsoft.Office.Interop.Excel' assembly in your project and of course use this as a guideline only -
using System;
using Microsoft.Office.Interop.Excel;
class MacroRunner
{
static void Main()
{
Application excelApp = new Application();
excelApp.Visible = true;
Workbook workbook = excelApp.Workbooks.Open(@"C:\Path\ToYour\Workbook.xlsm");
DisplayListOfMacros(workbook);
Console.Write("Enter the name of the macro you want to run -> ");
string selectedMacro = Console.ReadLine();
RunMacro(workbook, selectedMacro);
excelApp.Quit();
}
static void DisplayListOfMacros(Workbook workbook)
{
Console.WriteLine("Available Macros ->");
foreach (VBComponent component in workbook.VBProject.VBComponents)
{
Console.WriteLine(component.Name);
}
Console.WriteLine();
}
static void RunMacro(Workbook workbook, string macroName)
{
try
{
workbook.Application.Run(macroName);
}
catch (Exception ex)
{
Console.WriteLine($"Error running macro '{macroName}': {ex.Message}");
}
}
}