I have a problem when I try to run a vba script in excel file from C# application. My code is:
public void RunMacro(string path, string macro)
{
Excel.Application app = null;
Excel.Workbooks workbooks = null;
Excel.Workbook workbook = null;
app = new Excel.Application();
if (app == null)
return;
app.Visible = false;
ChangeCulture();
workbooks = app.Workbooks;
workbook = workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
LogWrapper.Debug("Run Macro start");
app.Run(macro, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing);
LogWrapper.Debug("Run macro finish");
workbook.Close(false, Type.Missing, Type.Missing);
app.Quit();
ReleaseObject(app);
ReleaseObject(workbook);
}
I run this method after click on the button in my web browser and the browser works all the time ("waiting for localhost..."). I can't see any requests in Firebug. My LogWrapper logs only first information ("Run Macro start"). In the Event Viewer has not any information about this execution. In the task manager process EXCEL.EXE uses 100% of processor. And I'm waiting for the result a half hour and still is nothing.
When I change vba script name to running I get error that the vba script was not found in the excel file. My vba script is very simple:
Sub start()
Range("A3").Select
ActiveCell.Value = "def"
Range("A4").Select
End Sub
Somebody know where I should search for information about this problem?