ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Launching solver in new Excel Instance (https://www.excelbanter.com/excel-programming/373646-launching-solver-new-excel-instance.html)

ariane2070

Launching solver in new Excel Instance
 
Hi,

I am trying to launch the excel Solver from a macro of workbook1 of an
excel instance MyXL1 in a workbook2 of another excel instance MyXL2,
and I cannot seem to get this right (the solver launches in the first
workbook)

I guess i have to add a reference to the workbook2 for SolverOK and
SolverAdd but how can I do that ??

Thank you in advance for any help you can give me!!!


With WorkBook1.VBProject.VBComponents("ForSolver").Code Module
NewCode = .Lines(1, .CountOfLines)
End With
With Workbook2.VBProject.VBComponents("ThisWorkbook").C odeModule
.DeleteLines 1, .CountOfLines
.AddFromString NewCode
End With
'copies a workbook_sheetselectionchange event that opens the solver
reference in the library

SolverReset

SolverOk SetCell:=Workbook2.ActiveSheet.Range("AT28:AT28"),
MaxMinVal:=3, ValueOf:="0",
ByChange:=Workbook2.ActiveSheet.Range(Workbook2.Ac tiveSheet.Cells(DebutPlage,
9), Workbook2.ActiveSheet.Cells(FinPlage, 9))

solveroptions Precision:=0.1
solveroptions Iterations:=10

For i = 18 To 29
SolverAdd CellRef:=Workbook2.ActiveSheet.Cells(28, i), Relation:=3,
FormulaText:="0"
Next i


Workbook2..ActiveSheet.Range("AT28:AT28").Select

MyXL.Application.Run "Solver.xla!SolverSolve"



All times are GMT +1. The time now is 01:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com