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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,676
Messages
6,173,757
Members
452,534
Latest member
autodiscreet

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