+ Reply to Thread
Results 1 to 28 of 28

Cannot access Solver

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Cannot access Solver

    I have Excel 2019. When trying to set up Solver in a worksheet I get the message:

    "Compile error in hidden module: Solver Code"

    It does show as active in "Active Application Add-ins"

    Can someone please tell me what to do to be able to use Solver.

    All help greatly appreciated.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Cannot access Solver

    Are you certain you have added a reference to Solver in VBA? See here: https://peltiertech.com/Excel/SolverVBA.html
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Thanks for your reply. I inserted the VBA script


    Private Sub Workbook_Open()
      
      Application.Run "Solver.xlam!Solver.Solver2.Auto_open"
     
    End Sub
    Into my Personal XLSB module following the suggestion from the link


    The error message still comes up, even after restarting Excel. Any ideas?

    Thanks again for helping me out.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Cannot access Solver

    By chance. Do you have any other add-in installed? It would help if you list your 3rd party add-ins.

    Some 3rd party add-ins been known to cause this error.
    If that's the case, you need to first uninstall the 3rd party add-in. Turn off Solver, and add it back in. And then install the 3rd party add-in.
    And see if that fixes. If not, you may need to remove the 3rd party add-in that may be in conflict.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  5. #5
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Thanks. I have no 3rd party app installed in Excel. Also Solver is checked in Tools/References of VBA.

    Strangely enough it appears to work on some workbooks but not others. Any idea why?

    Thanks for your help.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Cannot access Solver

    I expect that code opens the Solver add-in, but it doesn't set a reference to the Solver add-in. See this from the linked tutorial:
    Quote Originally Posted by Peltier
    To set a reference to an add-in, it must first be installed. Then on the VB Editor's Tools menu, select References. This lists all open workbooks and installed add-ins, as well as a huge list of resources installed on the host computer. Find the add-in in the list, and check the box in front of its name.

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Cannot access Solver

    In another place, Peltier talks about needing to set a reference to Solver in each workbook containing the Solver code. Is there one workbook invoking Solver, or is the Solver invoking code spread over multiple workbooks? If spread over multiple workbooks, does each workbook (each instance of the VBA code) have an active reference to Solver?

  8. #8
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Thanks Mr. Shorty. To illustrate I'm attaching workbook which has the Solver reference but still gives the error message. Does this help explain it?

    I appreciate your help.
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Cannot access Solver

    I did not find and VBA code in the file, and this file does not have a reference to Solver. I see no Solver model stored. It's possible that this is because I am using an older version of Excel (but that usually doesn't block all code from loading). We might need someone with a newer version of Excel to check and see if they can confirm what I am seeing.

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Cannot access Solver

    @MrShorty
    It's possible that this is because I am using an older version of Excel
    Nah. I can confirm that it is same on my machine (MS365, 64bit. Win10).

    I suspect issue lies somewhere in local environment and/or something else that is interfering with the add-in.

  11. #11
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Cannot access Solver

    I do have Microsoft Office 2019 and even if OP's file has an ".xlsm" extension I can't find no macros nor do I see any reference set to Solver in Visual Basic -> Tools -> Reference -> Solver. in the uploaded file looking at the solver setup I only see cell O2 set to min but how solver shall achieve this is not given by specifying "cells to change"

    Alf

  12. #12
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    I checked and the workbook prior to attaching it did have the Visual Basic -> Tools -> Reference -> Solver box checked. For some reason the process of uploading it caused the check to be removed. Any reason for this?

    My simple model sets Cell O2 to minimum by changing cell J2. It works on another workbook, but only on the top sheet.

    I am attaching a new workbook, this time containing the code supplied by Peltier. It doesn't appear to help, and the Solver check mark has been removed.

    Thanks to everyone who helped.
    Attached Files Attached Files

  13. #13
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Cannot access Solver

    I see the code in the "sheet1" sheet module. I notice that Peltier stores this code in a regular module (not a sheet module). I don't know if it makes any difference, but I know that some procedures (UDF procedures, for example) work best from a regular module rather than a sheet module.

    When I open Trial2, there is no reference to Solver. I'm not sure why Excel is not saving the reference with the file (others verify???).

    You did not include your actual Solver procedure that invokes Solver, so I cannot test it. My expectation is that, if you set the reference to Solver, your debugged code should work fine, but I cannot test it.

    I looked at your problem. Is this an accurate representation of your real problem? I notice that this problem is relatively easy to solve algebraically, which means that Solver is not even needed for this problem. If this is not representative and you're certain that Solver is needed for the real problem, then we can continue. If this is representative of the real problem, I would spend a few minutes with the algebra of the problem, solve the problem for J2 (rate2), and plug that formula into Excel, and abandon Solver.

  14. #14
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Thanks again MrShorty for your patience.

    1.- As I mentioned, the file prior to uploading here does contain a check in Visual Basic -> Tools -> Reference -> Solver. Unfortunately the upload procedure is somehow removing it.

    2.- The (very simple) procedure is:

    Set Objective: $O$2
    To: Min
    By changing variable cells : $J$2

    I'm not trying to invoke Sover via VBA, I'm fine running it "by hand" but the problem is I get the error message from clicking Data ->Solver, so even that is not an option.

    Thanks again for staying with me on this.

  15. #15
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,534

    Re: Cannot access Solver

    Programmernovice, can you attach the version of the Solver.xlam file you have? I want to look at the file and determine the cause of the error. Please zip it to a ZIP file before uploading, as the forum does not provide the option to attach XLAM.

    Artik

  16. #16
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Thanks Artik. Have attached file.

    I appreciate your help.
    Attached Files Attached Files

  17. #17
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Cannot access Solver

    The UDF function in file Trial2.xlsm just checks if the add-in solver is installed in Excel as solver are not added by default but it does not set a reference to solver in VBA. A must if solver should be run using a macro.

    You need a macro like this:
    Sub Macro1()
    ThisWorkbook.VBProject.References.AddFromFile "C:\Program Files\Microsoft Office\Office16\Library\SOLVER\SOLVER.XLAM"
    End Sub
    But before you run it you must allow access to Visual Basic Projects:

    Start Microsoft Excel.
    Open a workbook.
    Click File and then Options.
    In the navigation pane, select Trust Center.
    Click Trust Center Settings....
    In the navigation pane, select Macro Settings.
    Ensure that Trust access to the VBA project object model is checked.
    Click OK.
    As for you model you must tell solver what cell or cells it can change to reach the target value (Max value) of cell O2 and changing the value of this cell(s) must have an impact on the O2 value.

    Alf
    Last edited by Alf; 05-05-2022 at 09:27 AM.

  18. #18
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Thanks Alf for your help. Taking your suggestions in order:

    1.- For some reason adding workbook here removes the Visual Basic -> Tools -> Reference -> Solver check, which is present in the file I uploaded.

    2.-I inserted the code you suggested in workbook. I get message "Name conflicts with existing module, project or object library".

    3.- I'm trying to run Solver "by hand", that is to say without VBA to call Solver in. The model is

    Set Objective: $0$2
    To: Min
    By changing variable cells: $J$2

    As I mentioned, it runs on the top sheet of one workbook, but not in any others.

    Thanks for your thorough assistance

  19. #19
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Cannot access Solver

    I apologize. I had the impression that the main concern was not being able to access Solver from VBA. If you are also unable to call Solver manually, that suggests to me some problem in your Office installation -- Solver is not installed to the correct location or something else that prevents Excel from finding the Solver add-in even though it is installed.

    I know it gets cliche, but the only thing I can think to do is to repair or reinstall Office. I've never had trouble accessing Solver manually.

  20. #20
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Well MrShorty, it is not cliche at all, I did the repair. After trying to manually run Solver I still get

    "Compile error in hidden module: SolverCode.
    This error commonly occurs when code is incompatible with the
    version, platform, or architecture of this application. Click "Help" for
    information on how to correct this error."

    After clicking "Help" I get
    "Your organization's administrator turned off the service required to use this feature"

    I guess it's not worth anyone's time to keep plugging away at this thing. As you pointed out, for this simple problem one can change the variable cell manually to get an approximate solution.

    I appreciate your help with this.

  21. #21
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Cannot access Solver

    Modified you Trial file and added two macros. Macro Access sets link to solver.xlam file. Must allow macro Access to make change in Trust Centre if needed.

    Macro "SolvMacro" runs solver changing the value in cell O2 to zero i.e. min value as you use formula ABS on cell O2 by setting J2 to 3,24 %

    In case macro disappear due to upload it looks like this:

    Sub SolvMacro()
      
       SolverReset
        SolverOk SetCell:="$O$2", MaxMinVal:=2, ByChange:="$J$2", Engine:=1
        SolverSolve UserFinish:=True
    End Sub
    Alf
    Attached Files Attached Files

  22. #22
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Well, I'll be dammed, and pardon the bad language. Your SolveMacro() solved the problem. For any other problem, all one has to do is change the Solver parameters to what's needed.

    Additionally, I found that the code must be inserted in every worksheet within a workbook, in order for it to work in the entire workbook. Go figure. It did not work by inserting it into the Personal.XLSB module at launching Excel.

    Thanks Alf for your help, it's greatly appreciated!

    PS I don't particularly care for Excel 2019 either. I got it to have something newer, but don't want to pay for 365. What are your reasons?

  23. #23
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Cannot access Solver

    One could change the cell manually, but the non-Solver solution I proposed was an algebraic solution that should yield and exact solution (well, as exact as double precision floating point arithmetic can get when programmed into Excel). If you are having trouble with the algebra, we should be able to help with that (again, assuming the sample calculation you provided is truly representative of your actual calculation).

  24. #24
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Alf has provided a simple solution that actually allows Solver to run manually. Thanks again for your help.

  25. #25
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,534

    Re: Cannot access Solver

    ZipSolver.zip file is empty.

    Artik

  26. #26
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Sorry about that. Alf has provided a simple solution, as shown above. Thanks for your input.

  27. #27
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Cannot access Solver

    Thanks for feedback and rep

    Additionally, I found that the code must be inserted in every worksheet within a workbook, in order for it to work in the entire workbook
    Depends a bit on the solver model. If it is the same for every sheet you could loop through all sheets

    Sub LoopSheet()
    Dim i as Integer
    
    For i = 1 To Sheets.Count
    
    Sheets(i).Activate
    solver macro added here
    Next
    End Sub
    As solver always run from the Active Sheet you loop through the workbook and activate each sheet run solver on the active sheet and then activate the next sheet as i goes from 1 to 2 and so forth.

    PS I don't particularly care for Excel 2019 either. I got it to have something newer, but don't want to pay for 365. What are your reasons?
    I'm used to the Office version of Excel. Done 2003 as well as 2007 and was rather happy with 2010. Still struggling with excel 2019 but felt the need to upgraded because number of user for excel 2010 are quit small I think.

    Alf
    Last edited by Alf; 05-05-2022 at 01:38 PM.

  28. #28
    Forum Contributor
    Join Date
    09-12-2021
    Location
    Mexico
    MS-Off Ver
    Office 2019
    Posts
    169

    Re: Cannot access Solver

    Thanks again for your valuable help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 10-09-2020, 03:33 AM
  2. Replies: 2
    Last Post: 06-22-2020, 03:14 PM
  3. Access to changing statistics in SOLVER
    By Amir_12 in forum Excel General
    Replies: 0
    Last Post: 10-22-2018, 01:21 AM
  4. Replies: 1
    Last Post: 04-27-2016, 03:05 PM
  5. Replies: 0
    Last Post: 07-20-2014, 12:45 PM
  6. Can't start Solver. Error message says Solver.xlam already open.
    By DaveHills in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 10-21-2012, 11:02 AM
  7. Programatically access Excel's Solver?
    By Kevin R in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2005, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1