VBA solver add-in function

Posted on 2003-03-19
Medium Priority
Last Modified: 2013-12-25

I am working on VBA code in MS Project and I'm trying to add a reference to the Solver add-in to an excel sheet without manually having to add it by going to tools referneces. Everyting seems to work ok, the sover reference is added to the VBA project in excel, but VBA doesn't like the line:

with objExcel
.SolverOk SetCell:="$A$4", MaxMinVal:=3, ValueOf:="0", ByChange:="$A$3"
end wtih

I get the error message: Run-time error '438'. Object doesn't support this property or method.

I was wondering if there is any way of calling the solverOK function through MS project using an excel sheet as an object.

Here is the code I have:

Option Explicit
Dim objExcel As Object

Sub test()


End Sub

Sub Create_New_Instance_of_Excel()

Set objExcel = CreateObject("Excel.sheet")
Exit Sub

End Sub

Sub Workbook_Open()

Dim SolverPath As String

objExcel.Application.Visible = True
objExcel.Application.Cells(1, 1).Value = "Opened"
MsgBox "Workbook Opened"

SolverPath = "C:\Program Files\Microsoft Office\Office\Library\Solver\Solver.xla"
objExcel.VBProject.References.AddFromFile SolverPath

objExcel.Application.Cells(1, 1).Value = "Solver Added"
MsgBox "Solver Added"

End Sub

Sub runMe()

MsgBox "runMe"

With objExcel
.SolverOk SetCell:="$A$4", MaxMinVal:=3, ValueOf:="0", ByChange:="$A$3"

.Application.Cells(1, 1).Value = "runMe"
End With

MsgBox "runMe end"

End Sub
Question by:mcgerks
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Accepted Solution

Brendt Hess earned 2000 total points
ID: 8170046
Try this version:

Dim vBuffer As Variant

vBuffer = .Application.Run("Solver.xla!
SolverOK", "$A$4", 3, 0, "$A$3")

Expert Comment

ID: 9095645
No comment has been added lately (141 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to bhess1 http:#8170046

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --


EE Cleanup Volunteer


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question