I have a problem when I try to run a vba script in excel file from C# application. My code is:
当我尝试在C#应用程序的excel文件中运行vba脚本时,我遇到了问题。我的代码是:
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.
我在浏览器中单击按钮后运行此方法,浏览器始终有效(“等待localhost ...”)。我在Firebug中看不到任何请求。我的LogWrapper仅记录第一个信息(“运行宏启动”)。在事件查看器中没有任何有关此执行的信息。在任务管理器进程中,EXCEL.EXE使用100%的处理器。我等了半个小时的结果,但仍然没有。
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:
当我将vba脚本名称更改为运行时,我得到错误,即在excel文件中找不到vba脚本。我的vba脚本非常简单:
Sub start()
Range("A3").Select
ActiveCell.Value = "def"
Range("A4").Select
End Sub
Somebody know where I should search for information about this problem?
有人知道我应该在哪里搜索有关此问题的信息吗?
1 个解决方案
#1
0
It was a problem with permissions of IIS USER. When I change permission or turn on Windows authentication, everything is works.
这是IIS USER权限的问题。当我更改权限或打开Windows身份验证时,一切正常。
#1
0
It was a problem with permissions of IIS USER. When I change permission or turn on Windows authentication, everything is works.
这是IIS USER权限的问题。当我更改权限或打开Windows身份验证时,一切正常。