Hello!
I am working on a project, which the input data are from an excel workbook and then the result calculating by matlab are returned in another excel workbook. The m.file run correctly in Matlab and also return the values back in excel.
Now i am facing the problem to execute Matlab m.file from excel VBA without opening Matlab. I have looked up these related solutions on this forum and others, Spreadsheet Link EX i won't consider because my calculation in Matlab is 4-dimensions. I apply the solution from Johan (<http://www.mathworks.com/matlabcentral/answers/8684-running-a-specific-m-file-fig-from-excel)>.
However, until now there is still a problem. When i execute the excel macro to execute Matlab Application, the message 'Excel is waiting for another application to complete an OLE action.' comes out all the time. Afterwards i turn off the alert display in excel, then the error message 'Runtime Error 2147023170 (800706be): Automation Error The Remote Procedure Call Failed' appears.
The abstract of my m.file is:
enableservice('AutomationServer',true)
t1 = xlsread(filename,sheet,xlRange);
...
...
C = xlswrite(filename,sheet,xlRange);
The macro code in excel is like:
Sub runMatlab()
Dim hMatlab As Object
Dim sDir As String, cdsDir As String, s1 As String
Set hMatlab = CreateObject("Matlab.Application")
s1 = "'"
sDir = s1 & ActiveWorkbook.Path & s1
cdsDir ="cd(" & sDir & ")"
hMatlab.Execute(cdsDir)
Application.DisplayAlerts = False
hMatlab.Execute("Calculation")
Application.DisplayAlerts = True
ThisWorkbook.Close SaveChanges:=True
End Sub
Could someone give me a hint how to solve this problem? I will be really appreciate!