+ Reply to Thread
Results 1 to 2 of 2

Question about initializing Solver in VBA

  1. #1
    Registered User
    Join Date
    06-11-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    1

    Question about initializing Solver in VBA

    Hi everyone,

    I'm new to the forum and have just started dusting off some VBA I learned in school a few years ago to help me build an automated model for my company. One of the functions of the model uses a VBA script to call the Solver add-in. I have added code to check that Solver is installed when the workbook opens but have noticed that it's possible to get the compile error when the Solver reference isn't checked in VBA. I will be pushing this solution to a lot of people who aren't very knowledgeable and would like to avoid their needing to interact with the VBA interface.

    Is there a way to use VBA code to check the reference to Solver so people don't have to do this? If not, I'll create a screenshot tutorial that people can use in an instructions tab or something but it would be nice if I could just automate it.

  2. #2
    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,758

    Re: Question about initializing Solver in VBA

    Perhaps something like this may work:

    Add Solver in VB:

    Please note that it is important to set a correct reference.before Solver is
    loaded.
    An Add-Inn that does get loaded becomes "active." Without a correction,
    "ActiveWorkbook.whatever..." would point to the Add-Inn itself. (an error)

    Sub SolverLoad()
    '// Adds Solver
    Dim wb As Workbook
    On Error Resume Next

    '// *** Set to the correct workbook!
    Set wb = ActiveWorkbook

    If Not AddIns("Solver Add-In").Installed Then AddIns("Solver
    Add-In").Installed = True
    wb.Activate
    wb.VBProject.References.AddFromFile Application.LibraryPath &
    "\SOLVER\SOLVER.XLAM"
    End Sub
    Don't know who wrote this scrip (probably Dana DeLouis) and have no idea if this will work with Excel 2013

    Alf
    Last edited by Alf; 06-12-2013 at 01:13 AM. Reason: adding possible author of script

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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