C
CodeMonkey
Hi all
I want to load and reference solver in a spreadsheet if its not already
referenced/opened, but I am having some problems.
Here's my code below. I find that SolverInstall runs ok, but if Solver
is not referenced already from VBA or is MISSING, then SolverAutoOpen
fails with the project not referenced. I have to save the workbook
after running SolverInstall and then close/reopen it for solver to be
referenced properly. I am running the SolveIt macro below from a Vb6
application. Can anyone help with a foolproof way to get Solver always
referenced and loaded first time (from vb6)?
Thanks
Andrew
Dim sh1 as worksheet
Sub SolveIt()
SolverInstall
SolverAutoOpen
sh1.Activate
SolverOk SetCell:="$K$63", MaxMinVal:=2, ValueOf:="0",
ByChange:="$K$54:$K$61"
SolverSolve UserFinish:=True
End Sub
Sub SolverInstall()
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
Sub SolverAutoOpen()
If Not SOLVER.AutoOpened Then
SOLVER.Auto_open
End If
End Sub
I want to load and reference solver in a spreadsheet if its not already
referenced/opened, but I am having some problems.
Here's my code below. I find that SolverInstall runs ok, but if Solver
is not referenced already from VBA or is MISSING, then SolverAutoOpen
fails with the project not referenced. I have to save the workbook
after running SolverInstall and then close/reopen it for solver to be
referenced properly. I am running the SolveIt macro below from a Vb6
application. Can anyone help with a foolproof way to get Solver always
referenced and loaded first time (from vb6)?
Thanks
Andrew
Dim sh1 as worksheet
Sub SolveIt()
SolverInstall
SolverAutoOpen
sh1.Activate
SolverOk SetCell:="$K$63", MaxMinVal:=2, ValueOf:="0",
ByChange:="$K$54:$K$61"
SolverSolve UserFinish:=True
End Sub
Sub SolverInstall()
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
Sub SolverAutoOpen()
If Not SOLVER.AutoOpened Then
SOLVER.Auto_open
End If
End Sub