Running a MatLab program from Excel with VBA

Lola7

New Member
Joined
Jul 16, 2014
Messages
1
Hi,
I'm trying to run my MatLab program called regressionv3 from Excel with the following VBA code:

Call RunMatLab(regressionv3)

Sub RunMatLab(currPrgm)
Dim hMatlab As Object
Dim sDir As String, cdsDir As String, s1 As String
Dim Result As String
Set hMatlab = CreateObject("matlab.application")
s1 = "'"
sDir = s1 & runPath & s1
cdsDir = "cd(" & sDir & ")"
hMatlab.Execute (cdsDir)
Result = hMatlab.Execute(currPrgm)
If Result <> "" Then MsgBox Result


End Sub

The problem is that, during debug, I get the message regressionv3 = empty. When I run the code, I see the MatLab window flicker open and then close before it runs the program, and I do not get the output I expect (because the program is not running). Regressionv3 runs alright from MatLab, but if anyone can tell me how to make it run from Excel with this/more efficient code, I would appreciate it very much.
Thank you!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top