I'm trying to gather a Ms Project tasks' durations from Matlab through a VBA function. The idea is to gather all durations in an array (variant in VBA), and then transfer this variable to matlab by calling a function. The VBA code includes a Subprocess and a function. I can invoKe the Subprocess from matlab, but it does not return any value since is a subprocess, not a function. However, when I directly invoke the function, I get an error.
The VBA code is:
Sub TsksDur()
Dim TsksDur As Variant
Dim x As Long
TsksDur = GatherTsksDur()
End Sub
Public Function GatherTsksDur()
Dim TsksDur As Variant
Dim x As Long
Dim Tsk As Task
'Resize Array prior to loading data
ReDim TsksDur(ActiveProject.Tasks.Count)
'Loop through each cell in Range and store value in Array
For Each Tsk In ActiveProject.Tasks
TsksDur(x) = Tsk.Duration
x = x + 1
Next Tsk
'Print values to Immediate Window (Ctrl + G to view)
'For x = LBound(TsksDur) To UBound(TsksDur)
'Debug.Print TsksDur(x)
'Next x
GatherTsksDur = TsksDur
The matlab code is:
MSP_a = actxserver('MSProject.Application');
invoke(MSP_a,'FileOpen',[out_path filesep fname fext]); % Open the Ms Project defined by fname
TskDur=invoke(MSP_a,'Run','TsksDur'); % Runs properly but returns nothing
TskDur=invoke(MSP_a,'Run','GatherTsksDur'); % Does not work
Anyone can help me understanding what is happening, and how to solve this problem?
Thanks, Jorge