MATLAB: Do I receive a type mismatch error when using MLGETVAR in Excel VBA

Spreadsheet Link

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

Best Answer

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.