Enable Solver Add-in
Before you can use the Solver VBA functions from VBA, you must enable the Solver add-in in the Excel Options dialog box.
- Click the File tab, and then click Options below the Excel tab.
- In the Excel Options dialog box, click Add-Ins.
- In the Manage drop-down box, select Excel Add-ins, and then click Go.
- In the Add-Ins dialog box, select Solver Add-in, and then click OK.
Another way to enable the Solver Add-in: Click the Developer tab > Add-Ins group > Excel Add-ins > Solver Add-in.
After you have enabled the Solver add-in, Excel will auto-install the Add-in if it is not already installed, and the Solver command will be added to the Analyze group on the Data tab in the ribbon.
Enable Solver In VBE
Before you can use the Solver VBA functions in the Visual Basic Editor, you must establish a reference to the Solver add-in. In the Visual Basic Editor, with a module active, click References on the Tools menu, and then select Solver under Available References.
If Solver does not appear under Available References, click Browse, and then open Solver.xlam
in the C:\Program Files\Microsoft Office\root\Office16\Library\SOLVER
(Office 2021 on Windows 10) subfolder.
The Solver VBA Functions
The following functions can be used to control the Solver add-in from VBA. Each function corresponds to an action that you can perform interactively, through the Solver Parameters, Solver Options, and Solver Results dialog boxes of the Solver add-in.