Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel, Macro, References 1

Status
Not open for further replies.

tab245

Technical User
Sep 17, 2002
13
US
Hi!

I am looking for a code that would automatically include reference to an Excel macro.
Currently, I need to go to Tools-References in VBA to include a reference. But, maybe, there is a way to code this?


Thanks!
 

With ThisWorkbook.VBProject.References
.AddFromFile &quot;<path to reference>&quot;
End With

HTH
 
Yaha!!!

this works!
Thank you!

the only problem is that I can not add a reference and execute a function from the reference in the same sub. But this is fine - I can put them into different macros and run sequentially.



Here is what I have:
---- add the reference on SOLVER
Sub ss3()
With ThisWorkbook.VBProject.References
.AddFromFile &quot;C:\ProgramFiles\MicrosoftOffice\Offi ce10\Library\Solver\SOLVER.XLA&quot;
End With
End Sub

----- run solver
Sub ss4()

'set objective function
SolverOk SetCell:=&quot;$B$6&quot;, MaxMinVal:=2,ValueOf:=&quot;0&quot;, ByChange:=&quot;$B$1:$B$3&quot;

'set constraints
SolverAdd CellRef:=&quot;$B$5&quot;, Relation:=3, FormulaText:=&quot;$G$5&quot;

'set options
SolverOptions MaxTime:=1000, Iterations:=10000, Precision:=0.000001, _
AssumeLinear:=False, StepThru:=False, Estimates:=1, Derivatives:=1, _
SearchOption:=2, IntTolerance:=5, Scaling:=False, Convergence:=0.0001, _
AssumeNonNeg:=True

' Do not display the Solver Results dialog box.
SolverSolve UserFinish:=True

' Finish and keep the final results.
SolverFinish KeepFinal:=1

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top