A
ariane2070
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").CodeModule
NewCode = .Lines(1, .CountOfLines)
End With
With Workbook2.VBProject.VBComponents("ThisWorkbook").CodeModule
.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.ActiveSheet.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"
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").CodeModule
NewCode = .Lines(1, .CountOfLines)
End With
With Workbook2.VBProject.VBComponents("ThisWorkbook").CodeModule
.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.ActiveSheet.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"