?
Solved

VBA solver add-in function

Posted on 2003-03-19
2
Medium Priority
?
970 Views
Last Modified: 2013-12-25
Hi,

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"
.SolverSolve
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()

Create_New_Instance_of_Excel
Workbook_Open
runMe

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"
.SolverSolve

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

MsgBox "runMe end"

End Sub
0
Comment
Question by:mcgerks
[X]
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
2 Comments
 
LVL 32

Accepted Solution

by:
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")
0
 
LVL 2

Expert Comment

by:cerebralpc
ID: 9095645
mcgerks,
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 ! --

Thanks,

cerebralpc
EE Cleanup Volunteer

http://www.experts-exchange.com/Q_20556582.html
0

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