locked
User-function does not work in Excel.Application RRS feed

  • Question

  • I has a Excel.Application object.I use it to open a file named abc.xlsx which has some user-function created by VBA or C# .The abc.xlsx worked OK if I open it in my desktop.But user-function does not work when I use Excel.Application to open it.The user-function get sum of two int.It is so easy.The code to open abc.xlsx is:

    Excel.Application app = new Excel.Application();

    app.Visible = false;
    app.Workbooks.Open("E:\\ExcelTest\\abc.xlsx");

    Why my function does not work? What is wrong?

    I am sorry to my English.I hope somebody can help me.

    Email/MSN:lossage@126.com

    Thanks for your help.
    • Moved by Cindy Meister MVP Saturday, January 5, 2013 5:43 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Saturday, January 5, 2013 3:29 PM

Answers

  • Hi 

    Thank you for posting in the MSDN Forum.

    Could you please tell me where do you want to use the function? Do you mean that you want to put the function into a cell?

    Suppose you have 2 numbers in Cell A1 and Cell B1 and you want to put the Sum of them in C1. You can use

    Worksheet.Range["C1"].Formula = "=SUM(A1, B1)";

    Hope it helps. If you still have any confusion, please feel free to let me know.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Quist Zhang Monday, January 14, 2013 2:19 PM
    • Marked as answer by Quist Zhang Wednesday, January 16, 2013 6:28 AM
    Monday, January 7, 2013 12:12 PM

All replies

  • You likely don't have it in a Public module declared as Public.

    Also, how are you testing the function in your code ?

    Saturday, January 5, 2013 6:44 PM
  • 1:I had put it in a Public module.And it worked correctly in anyother xlsx file while I double-click to open those xlsx file.

    2:After my code open a xlsx file, I can see it does not work correctly.It displayed "#NAME?" in cell and "'C:\Users\Lossage\AppData\Roaming\Microsoft\AddIns\ExcelTest.xla'!MyTestVBAFun(A1,B1)" in function bar 

    Can you make it work correctly?And do you have any example?

    Sunday, January 6, 2013 1:54 AM
  • Open ExcelTest.xla and look for MyTestVBAFun in a MODULE.

    Is it declared PUBLIC ?

    Also, does it have 2 parameters specified ?

    • Edited by Syswizard Sunday, January 6, 2013 5:25 PM
    Sunday, January 6, 2013 5:25 PM
  • Yes.In a MODULE.Decared public.Have 2 parameters.
    And it is worked correctly while using shell-execute or create-process to start excel.
    But it does not work correctly while I using COM as Excel Interop to start excel .



    • Edited by 孟冬 Monday, January 7, 2013 1:32 AM
    Monday, January 7, 2013 1:31 AM
  • Then I'll bet you need to instantiate some class and call a method to execute that function from witin a COM component.
    Also, you may have to reference the exact module name as well.
    Sorry, I can't help with this...beyond my expertise.
    Monday, January 7, 2013 12:07 PM
  • Hi 

    Thank you for posting in the MSDN Forum.

    Could you please tell me where do you want to use the function? Do you mean that you want to put the function into a cell?

    Suppose you have 2 numbers in Cell A1 and Cell B1 and you want to put the Sum of them in C1. You can use

    Worksheet.Range["C1"].Formula = "=SUM(A1, B1)";

    Hope it helps. If you still have any confusion, please feel free to let me know.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Quist Zhang Monday, January 14, 2013 2:19 PM
    • Marked as answer by Quist Zhang Wednesday, January 16, 2013 6:28 AM
    Monday, January 7, 2013 12:12 PM