You can load a saved Solver model in VBA and re-run it in two lines: call SolverLoad with the saved range name, then call SolverSolve. The saved model has to exist first (Solver's Save Model writes it into a worksheet range as a vertical block of labeled cells), and the Solver add-in reference must be set in your project or the calls will fail with a compile error. That is the whole trick: Excel does not keep Solver settings in memory between sessions, so Save Model/Load Model or SolverSave/SolverLoad is the only reliable way to persist target cell, variable cells, constraints, and options.

What You'll Need

  • Excel with the Solver add-in enabled: File > Options > Add-ins, Manage: Excel Add-ins, Go, tick Solver Add-in. (Menu labels vary slightly by version and region.)
  • A workbook where you have already built and solved a model at least once, so the Solver engine is installed and working.
  • Macro security permission to run VBA. Save as .xlsm (macro-enabled), otherwise your code is discarded on close.
  • A named range reserved for the saved model, ideally on a hidden or clearly labeled sheet, because the block is ugly and can be overwritten accidentally.
  • Optional but recommended: a cell to hold the model range address so the code and the model stay in sync.

Step-by-Step

  1. Save the model once through the Solver dialog. Open Data > Solver, set Objective, By Changing Variable Cells, constraints and options, then click Solve. When the results box appears, choose Keep Solver Solution. This proves the model is valid before you automate anything.
  2. Save the model definition to a range. In the Solver Parameters dialog, open Options, and look for Save Model (in some versions it is a button in the Parameters dialog itself; in the newer dialog it sits in the Options area). Point it at a spare range, for example $Z$1:$Z$60, on a sheet named SolverStore. Excel writes the objective, variable cells, constraints, and option flags there, with labels in column A of the block. If Solver refuses because the range is too small, widen it; models with many constraints need many rows.
  3. Name the range. Select the block and use Formulas > Define Name, or select it and type a name in the Name Box, for example SolverModelA. Names cannot contain spaces. This name is what SolverLoad expects, not an address.
  4. Enable the Solver reference. In the Visual Basic Editor, go to Tools > References and tick Solver. If it is missing, browse to the Solver add-in file installed with Office. Without this, SolverLoad and SolverSolve are not recognized.
  5. Write the loading routine. In a standard module, add:
    Sub RunSavedModel()
        Dim rc As Integer
        rc = SolverLoad(True, Range("SolverModelA"))
        If rc <> 0 Then
            MsgBox "SolverLoad failed with code " & rc
            Exit Sub
        End If
        rc = SolverSolve(UserFinish:=True)
        If rc = 5 Then MsgBox "Solver could not find a feasible solution."
    End Sub
    The first argument of SolverLoad is LoadArea: True means the model is stored as a named range; use False and pass the address string when the model lives in a plain range.
  6. Test on a copy. Run the macro on a duplicate workbook with known inputs, confirm the variable cells changed and the objective matched what the dialog produced manually. Compare both solutions cell by cell.
  7. Handle the result code. SolverSolve returns a number: 0 means it solved, 1 means it stopped at an iteration or time limit, 2 means it could not improve, 4 and 5 mean no feasible solution or divergent/unbounded. Branch on the value instead of assuming success, and write it into a log cell so you can audit later runs.
  8. Suppress the results dialog when running unattended. Pass UserFinish:=True so Solver does not ask whether to keep the solution. To take the answer without applying it, add ShowRef:=False and read the returned values, then decide whether to keep them.
  9. Optionally re-save after changes. If your macro edits constraints (say, by writing new limit values into cells and rebuilding the model), call SolverSave(True, Range("SolverModelA")) at the end so the stored block matches the live settings. Otherwise the next load silently restores the old model.

Common Mistakes

  • Passing a range address where SolverLoad expects a name, or the reverse. Mixing up LoadArea True/False is the single most common cause of failure code 100 or 101.
  • Storing the model block inside a range the macro later clears or sorts. Su {