Why do I receive a type mismatch error when using MLGETVAR in Excel VBA?

2 views (last 30 days)
I am using MLGETVAR command in my Excel VBA macro to get a variable from MATLAB workspace to Excel. However, when I try using the following code (from the documentation) I receive a VBA popup error message.
Sub Fetch()
Dim DataJ As Double
MLGetVar "J", DataJ
End Sub
Run-time error '13':
Type mismatch

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This change has been incorporated into the documentation in Release 2009a (R2009a). For previous releases, read below for any additional information:
The type mismatch error is due to the type of the variable (DataJ) that is used to hold the value returned by the MLGETVAR command.
To work around this issue, try one of the options below:
1. Declare the variable to be of type Variant, as shown below:
Sub Fetch()
Dim DataJ As Variant
MLGetVar "J", DataJ
End Sub
2. Do not declare the variable at all. The MLGetVar function will create one of type Variant.

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2008a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!