使用C#:打开Excelbook(* .xlsb)并运行宏 [英] With C#: Open Excelbook (*.xlsb) and run macro
问题描述
我想打开一个包含名为auto_open的宏的excelbook并运行此宏。
通常,当工作簿打开时,auto_open宏将自动运行,但是当使用c#打开excelbook时,它显然没有。
我有这个代码打开excelbook:
void OpenExcelFile()
{
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = true ;
string workbookPath = @ c:\\ \\Users\mko\Documents\Tidsregistrering\Tidsregistrering.xlsm跨度>;
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
0 , false , 5 , , , false ,Excel.XlPlatform .xlWindows, ,
true , false , 0 , true , false , false );
}
我发现了这个:
http://stackoverflow.com/questions/14248592/running -an-excel-macro-via-c-run-a-macro-from-one-workbook-on-another
并且可以看到RunMacro(oExcel,new Object [] {Worksheet01.xlsm!First_Macro});
其中first_macro可能是我的宏,应该能够运行宏。
但是runMacro来自dll Microsoft.Hpc.Excel(在Microsoft.Hpc.Excel.dll
中,并且在我的计算机上无处可寻。
我可以下载吗?但是在哪里?
你看到了吗? [ ^ ]
学会有效地使用Google。 [ ^ ]
找到另一个没有下载HPC的解决方案:
oXL = < span class =code-keyword> new Excel.Application();
oXL.Visible = true ;
oWB =(Excel._Workbook)(oXL.Workbooks.Open( @ c:\ Excelbook with macro.xlsm,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing .Value,Missing.Value,Missing.Value,Missing.Value));
oWB.RunAutoMacros(XlRunAutoMacro.xlAutoOpen);
I would like to open an excelbook containing a macro called "auto_open" and run this macro.
Normally the auto_open macro will run automaticly when the workbook is open, but when using c# to open the excelbook, it apparently does not.
I have this code to open the excelbook:
void OpenExcelFile()
{
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = true;
string workbookPath = @"c:\Users\mko\Documents\Tidsregistrering\Tidsregistrering.xlsm";
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
}
I have found this:
http://stackoverflow.com/questions/14248592/running-an-excel-macro-via-c-run-a-macro-from-one-workbook-on-another
and can see that RunMacro(oExcel, new Object[]{"Worksheet01.xlsm!First_Macro"});
where "first_macro" could be my macro, should be able to run the macro.
But runMacro comes from the dll Microsoft.Hpc.Excel (in Microsoft.Hpc.Excel.dll
and that is no where to be found on my computer.
Could I download ? but where ?
Did you look here?[^]
Learn to use Google effectively.[^]
Found another solution without downloading HPC:
oXL = new Excel.Application(); oXL.Visible = true; oWB = (Excel._Workbook)(oXL.Workbooks.Open(@"c:\Excelbook with macro.xlsm", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); oWB.RunAutoMacros(XlRunAutoMacro.xlAutoOpen);
这篇关于使用C#:打开Excelbook(* .xlsb)并运行宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!