I am trying to invoke one macro which is in Excel file. Below is the code which I got, but on running below it throws exception, with below message.
Code:
// Define your Excel Objects
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook = null;
try
{
//Start Excel and open the workbook.
xlWorkBook = xlApp.Workbooks.Open(@"C:\MyFolder\Junk\macro\xxxxxReport.xlsm");
//Run the macros by supplying the necessary arguments
xlApp.Run("LookupHLink");
//xlWorkBook.Save();
//Clean-up: Close the workbook
xlWorkBook.Close(false);
//Quit the Excel Application
xlApp.Quit();
}
catch (Exception ex)
{
}
finally
{
//~~> Clean Up
releaseObject(xlApp);
releaseObject(xlWorkBook);
}
There is no parameter for the macro.
Public Sub LookupHLink()
Error message:
Cannot run the macro 'LookupHLink'. The macro may not be available in this workbook or all macros may be disabled.
Please let me know if I am doing anything wrong.
xlApp.Run("Sheet1.LookupHLink");whereSheet1is the name of the worksheet module.