VBA code to add a reference to solver

T

Tbeek

I what a piece of VBA code that will add a reference to solver.
I would put it in a sub or function that uses solver

Thank
 
T

Tbeek

I would like to create the reference to solver in VBA that would b
equivalent to:
From the Visual Basic Editor, Tools, References, CheckMark Solver
click OK.

I am making a function that uses solver and I want to distribute it t
my colleagues but I don't want to have to go to their pc and tur
solver on and reference it. I would like the function to do it befor
it calls solver.
If there was a good way to check that solver was installed an
referenced, I could also use that so the function wouldn't have t
install and reference solver every time the function was used in
worksheet
 
D

Dana DeLouis

Sub SolverInstall()
On Error Resume Next
Dim wb As Workbook
Dim SolverPath As String

' Set a Reference to the workbook that will hold Solver
Set wb = ActiveWorkbook

SolverPath = Application.LibraryPath & "\SOLVER\SOLVER.XLA"

With AddIns("Solver Add-In")
.Installed = False
.Installed = True
End With

'Solver itself has 'focus' at this point.
'Make sure you point to the correct Workbook for Solver
wb.VBProject.References.AddFromFile SolverPath
End Sub

HTH. :>)
 
T

Tom Ogilvy

Read the article - it tells you how to create a reference programmatically.
Knowing that, you should be able to adapt it to create a specific reference
for solver. Giving a dick and jane explantion of what you want to do is
unnecessary as you already stated what you wanted to do in your original
question. Using the information in the article would also give you the
insights to determine if the reference already exists. You would just loop
through the references collection and test if any of the references are for
solver (and that if so, it isn't broken).
 
D

Dana DeLouis

You may prefer this other version that I use. HTH. :>)

Sub SolverInstall()
'// Dana DeLouis
Dim wb As Workbook

On Error Resume Next
' Set a Reference to the workbook that will hold Solver
Set wb = ActiveWorkbook

With wb.VBProject.References
.Remove .Item("SOLVER")
End With

With AddIns("Solver Add-In")
.Installed = False
.Installed = True
wb.VBProject.References.AddFromFile .FullName
End With
End Sub


--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


Dana DeLouis said:
Sub SolverInstall()
On Error Resume Next
Dim wb As Workbook
Dim SolverPath As String

' Set a Reference to the workbook that will hold Solver
Set wb = ActiveWorkbook

SolverPath = Application.LibraryPath & "\SOLVER\SOLVER.XLA"

With AddIns("Solver Add-In")
.Installed = False
.Installed = True
End With

'Solver itself has 'focus' at this point.
'Make sure you point to the correct Workbook for Solver
wb.VBProject.References.AddFromFile SolverPath
End Sub

HTH. :>)
 
Top