MATLAB: When passing “varargin” to a deployed Builder for Excel or Builder for .NET generic COM component, how to pass an empty “varargin” from VBA

MATLAB Builder NE

This question concerns examples in the R2007a documentation:
Help Navigator -> Contents -> MATLAB Builder for .NET -> Programming with COM Components -> Passing Arguments ->
Creating and Using a varargin Array in Visual Basic Programs
Creating and Using varargout in Visual Basic Programs
In MATLAB, "varargin" inputs to functions are optional, and may be present or omitted from the function call. However, from VBA, function signatures are more strict – if "varargin" is present among the MATLAB function inputs, the VBA call must include "varargin", even if it is desired to leave it empty. How can an empty "varargin" be passed in from VBA code?

Best Answer

This change has been incorporated into the documentation in Release 2009a (R2009a). For previous releases, read below for any additional information:
An empty "varargin" be passed in from VBA code as "Null". For example, suppose your MATLAB function signature is:
function b = foo(a,varargin)
VBA code which calls this deployed function, for an imaginary COM component named "mycomponent" containing a class "myclass" and versioned 1.0, with an empty varargin is:
Dim aClass As Object
Dim b As Variant
Dim a As Variant
'Initialize b here
'Initialize a here
aClass = CreateObject("mycomponent.myclass.1_0")
Call aClass.foo(1,b,a,Null)