using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
namespace ConsoleApp9
{
internal class Program
{
static void Main(string[] args)
{
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = true;
try
{
Excel.Workbook workbook = excelApp.Workbooks.Open(@"C:\Users\Administrator\Documents\test.xlsm");
try
{
excelApp.Run("'test.xlsm'!test1","test");
}
catch (Exception ex)
{
Console.WriteLine("Error running macro: " + ex.Message);
}
finally
{
Console.ReadKey();
workbook.Save();
workbook.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("Error opening workbook: " + ex.Message);
}
finally
{
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
}
Console.ReadKey();
}
}
}