Avatar of Ondrejovic
Flag for Slovakia asked on

Using Solver from Access

I want to call Solver on excel-file from  Access-VBA.
(I have created excel-file with data  and I would like to finalize it with Solver Addon.)

How should I do it?
(I didn't find any help on Internet.)

(I have Access 2007)
Microsoft AccessMicrosoft Excel

Avatar of undefined
Last Comment

8/22/2022 - Mon
Kent Dyer

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

thanx :)

Correct example is attached.
Sub Solver()

'set reference to excel object library
'AddIns("solver add-in").Installed = True
Dim objXL As Excel.Application
Dim strText As String
Dim blnCheck As Boolean
Set objXL = CreateObject("Excel.Application")
strText = objXL.Application.LibraryPath

Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

With objXL
    .Visible = True
    .Application.DisplayAlerts = False
    .Workbooks.Open (strText & "\solver\solver.xlam")
    .Application.DisplayAlerts = True
    .Workbooks("SOLVER.XLAM").RunAutoMacros 1
    .Application.ScreenUpdating = True
    Set wb = .Workbooks.Add
    Set ws = .Sheets.Add
    ws.Name = "Calculations"
    ws.Range("A1:A16") = 1
    ws.Range("A19").Formula = "=sum(A1:A16)"
    .Run "SOLVER.XLAM!SolverOk", ws.Range("$A$19"), 3, 50, ws.Range("$A$16")
    .Run "SOLVER.XLAM!SolverSolve", True
    .Run "SOLVER.XLAM!SolverFinish", KEEP
    .Application.ScreenUpdating = True
    .UserControl = True
    .Visible = True
End With
End Sub

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck