Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBA code to add a reference to solver

64 views
Skip to first unread message

Tbeek <>

unread,
Apr 6, 2004, 7:29:25 PM4/6/04
to
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

Thanks


---
Message posted from http://www.ExcelForum.com/

Tom Ogilvy

unread,
Apr 7, 2004, 9:27:07 AM4/7/04
to
http://support.microsoft.com/?id=160647
XL97: How to Programmatically Create a Reference

--
Regards,
Tom Ogilvy

"Tbeek >" <<Tbeek....@excelforum-nospam.com> wrote in message
news:Tbeek....@excelforum-nospam.com...

Tbeek <>

unread,
Apr 7, 2004, 9:49:34 AM4/7/04
to
I would like to create the reference to solver in VBA that would be
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 to
my colleagues but I don't want to have to go to their pc and turn
solver on and reference it. I would like the function to do it before
it calls solver.
If there was a good way to check that solver was installed and
referenced, I could also use that so the function wouldn't have to
install and reference solver every time the function was used in a
worksheet.

Dana DeLouis

unread,
Apr 7, 2004, 9:57:12 AM4/7/04
to
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. :>)
--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Tbeek >" <<Tbeek....@excelforum-nospam.com> wrote in message
news:Tbeek....@excelforum-nospam.com...

Tom Ogilvy

unread,
Apr 7, 2004, 11:01:07 AM4/7/04
to
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).

--
Regards,
Tom Ogilvy

"Tbeek >" <<Tbeek....@excelforum-nospam.com> wrote in message
news:Tbeek....@excelforum-nospam.com...

Dana DeLouis

unread,
Apr 7, 2004, 11:46:47 AM4/7/04
to
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" <del...@bellsouth.net> wrote in message
news:O4SkghKH...@TK2MSFTNGP10.phx.gbl...

0 new messages