MLGetVar

Write contents of MATLAB matrix in Microsoft Excel VBA variable

Syntax

MLGetVar ML_var_name, VBA_var_name
out = MLGetVar ML_var_name, VBA_var_name

Description

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.

out = MLGetVar ML_var_name, VBA_var_name lets you catch errors when executing MLGetVar. If MLGetVar fails, then out is a string containing error code. Otherwise, out is 0.

Input Arguments

ML_var_name

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.

VBA_var_name

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

Use VBA_var_name without quotes.

Output Arguments

out

0 if the command succeeded. Otherwise, a string containing error code.

Examples

expand all

Write the Contents of a MATLAB Matrix into a VBA Variable

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

Sub Fetch()
MLGetVar "J", DataJ
End Sub

See Also

Was this topic helpful?