none
Executing Solver via VB.Net. Error: Add method of AddIns class failed RRS feed

  • Question

  • I'm trying to run excel Solver addin via vb.net and im using the following code.

           

    Dim oExcel As Excel.Application
            Dim oBook As Excel.Workbook
            Dim oBooks As Excel.Workbooks
            Dim oSheets As Excel.Sheets
            Dim oSheet As Excel.Worksheet


            oExcel = CreateObject("Excel.Application")

            oBooks = oExcel.Workbooks

            oBook = oBooks.Open("D:\Sources\FeedFormula\FeedFormulaNew\FeedFormulaNew\bin\Debug\feed.xlsx")

            oExcel.AddIns.Add("C:\Program Files\Microsoft Office\OFFICE16\Library\SOLVER\SOLVER.XLAM")

            oExcel.DisplayAlerts = True

            oExcel.Run("Solver.xlam!Auto_Open")

    When i try running this code even though i have added the addin into excel and i have the solver specified file in this directory C:\Program Files\Microsoft Office\OFFICE16\Library\SOLVER\SOLVER.XLAM.  it says Add method of AddIns class failed. 

    when i run the excel file and use solver it works perfectly fine. so i know there no error in excel add in too. 

    Please help me out.

    thank you very much in advance.

    Lahiru



    Saturday, January 14, 2017 5:32 AM

Answers

  • Hi,

    I think there is no need to add the add-in because it is added by default.

    We need to load it if we want to use it.

     For Each myAddin In oExcel.AddIns
                If myAddin.Name = "SOLVER.XLAM" Then
                    myAddin.Installed = False
                    myAddin.Installed = True
                End If
            Next
    

    Besides, I think there is no macro named as Auto_Open in SOLVER.XLAM.

    You may get the exception:

    Cannot run the macro 'Solver.xlam!Auto_Open'. The macro may not be available in this workbook or all macros may be disabled.

    You could visit Using the Solver VBA Functions to check the available functions.

    Regards,

    Celeste



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 16, 2017 5:56 AM
    Moderator
  • Hi,

    I have no idea about how you want to use the Solver and in fact I have no experience to use the add-in, so sorry that I couldn’t  give a demo for you now.

    According to Excel Solver - Using Solver from VBA, the solver function would be recorded using macro recorder, so I suggest you record the macro to check what functions are used, then you could call the functions in your program.

    If you get the function name and don’t know how to adjust for your VB.NET program, please feel free to post threads. You could also ask for support from http://www.solver.com/support-overview. Portions of the Solver program code are copyright 1990-2009 by Frontline Systems according to MS official document.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 17, 2017 7:16 AM
    Moderator

All replies

  • Hi,

    I think there is no need to add the add-in because it is added by default.

    We need to load it if we want to use it.

     For Each myAddin In oExcel.AddIns
                If myAddin.Name = "SOLVER.XLAM" Then
                    myAddin.Installed = False
                    myAddin.Installed = True
                End If
            Next
    

    Besides, I think there is no macro named as Auto_Open in SOLVER.XLAM.

    You may get the exception:

    Cannot run the macro 'Solver.xlam!Auto_Open'. The macro may not be available in this workbook or all macros may be disabled.

    You could visit Using the Solver VBA Functions to check the available functions.

    Regards,

    Celeste



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 16, 2017 5:56 AM
    Moderator
  • Dear Celeste,

    First of all i must thank you for spending your valuable time to answer my question. I've used the above code there and as you stated the exception came saying Cannot run the macro 'Solver.xlam!Auto_Open'. The macro may not be available in this workbook or all macros may be disabled. I went thru the link you sent me on Using Solver VBA Function. I must say i was kind of lost there. Could you help me with the code to run solver. The values of the solver have been saved in the excel im going to execute via VB.net. In fact you just have to launch the solver and click install and then comes a Dialog  with Solver Parameters already in it.

    Then after comes a dialog box and you have to just press ok and it will give the values. Can you please be kind enough to give me the code for that. I'll be a big help. Im asking you this because im lost.

    p/s: I tried to add pics and i couldn't add because it said you cant add pictures or links until the account is verified.

    Thanking you again.

    Lahiru

    
    Monday, January 16, 2017 3:47 PM
  • Hi,

    I have no idea about how you want to use the Solver and in fact I have no experience to use the add-in, so sorry that I couldn’t  give a demo for you now.

    According to Excel Solver - Using Solver from VBA, the solver function would be recorded using macro recorder, so I suggest you record the macro to check what functions are used, then you could call the functions in your program.

    If you get the function name and don’t know how to adjust for your VB.NET program, please feel free to post threads. You could also ask for support from http://www.solver.com/support-overview. Portions of the Solver program code are copyright 1990-2009 by Frontline Systems according to MS official document.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 17, 2017 7:16 AM
    Moderator
  • Thank you very much! Ill see to it. :)
    Wednesday, January 18, 2017 4:55 PM
  • Hi,

    Since your original has been resolved, I suggest you mark helpful post as answer or you could share your solution here.

    Thanks for your understanding.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 19, 2017 6:45 AM
    Moderator