Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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 ?
Posted
Updated 23-Mar-15 18:37pm
v5

 
Share this answer
 
Comments
Koppelgaard 24-Mar-15 14:36pm    
Thanks for your google tricks:) I knew them, I must admid.
I try the Microsoft HPC Pack SDK download. That must solve my problem:)
Found another solution without downloading HPC:


C#
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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900