# Revision history [back]

### How to call from C# a basic macro defined in a calc document ?

I have written a C# program that opens a LibreOffice calc file, then writes data inside the file and then saves the file. The calc file contains a basic macro called MettreEnPage that is used to define the layout of the data. I want that my C# program calls the basic macro MettreEnPage. The piece of code is the following.

            Object aFuncInst = oServMan.createInstance("com.sun.star.sheet.FunctionAccess");
unoidl.com.sun.star.sheet.XFunctionAccess xFuncAcc = (unoidl.com.sun.star.sheet.XFunctionAccess)aFuncInst;
uno.Any[] aArgs = new uno.Any[1];
aArgs[0] = new uno.Any(0);
uno.Any aResult = xFuncAcc.callFunction("MettreEnPage", aArgs);


There is an exception when the function xFuncAcc.callFunction is called. The exception gives no information. My questions are the following:

• is it possible to call a basic macro defined in a calc file from a C# program ?
• If yes, what is the solution ?

 2 retagged Jim K 2758 ●5 ●21 ●44

### How to call from C# a basic macro defined in a calc document ?

I have written a C# program that opens a LibreOffice calc file, then writes data inside the file and then saves the file. The calc file contains a basic macro called MettreEnPage that is used to define the layout of the data. I want that my C# program calls the basic macro MettreEnPage. The piece of code is the following.

            Object aFuncInst = oServMan.createInstance("com.sun.star.sheet.FunctionAccess");
unoidl.com.sun.star.sheet.XFunctionAccess xFuncAcc = (unoidl.com.sun.star.sheet.XFunctionAccess)aFuncInst;
uno.Any[] aArgs = new uno.Any[1];
aArgs[0] = new uno.Any(0);
uno.Any aResult = xFuncAcc.callFunction("MettreEnPage", aArgs);


There is an exception when the function xFuncAcc.callFunction is called. The exception gives no information. My questions are the following:

• is it possible to call a basic macro defined in a calc file from a C# program ?
• If yes, what is the solution ?