Main Content


Write contents of MATLAB matrix in Microsoft Excel VBA variable


MLGetVar ML_var_name, VBA_var_name


MLGetVar ML_var_name, VBA_var_name writes the contents of MATLAB® matrix ML_var_name in the Excel® Visual Basic® for Applications (VBA) variable VBA_var_name. Creates VBA_var_name if it does not exist. Replaces existing data in VBA_var_name.

Input Arguments


Name of MATLAB matrix to access.

ML_var_name in quotes directly specifies the matrix name. ML_var_name without quotes specifies a VBA variable that contains the matrix name as a string. Do not use the MATLAB variable ans as ML_var_name. If defined, ML_var_name must be of type VARIANT. Any other type will give a "TYPE MISMATCH" error.


Name of VBA variable where the function writes the contents of ML_var_name.

Use VBA_var_name without quotes.


collapse all

Write the contents of the MATLAB matrix J into the VBA variable DataJ:

Sub Fetch()
MLGetVar "J", DataJ
End Sub
Introduced before R2006a