MATLAB: How I call the default method of a COM object in MATLAB 7.7 (R2008b)

MATLAB

I am using MATLAB as an ActiveX automation client. I receive an error when passing an input to an object, however the same object can take the same input value in Visual Basic.
For example, if I am using MATLAB to communicate with Excel, when I access the 'Column' property of a sheet and specify the column to be returned I receive an error.
With the following code
excelObj = actxserver('Excel.Application');
file = excelObj.workbooks.Open('test.xls');
sheet = excelObj.ActiveSheet;
cols = sheet.Columns('A:C');
I receive the error
??? Index exceeds matrix dimensions.
However, this syntax for specifying the range of columns to return, works in Visual Basic.

Best Answer

The ability to implicitly use the default property of a COM object is not available in MATLAB.
The issue is that Visual Basic has a concept of default properties. If an object is passed an input, this is the same as passing the input to the default property of that object. A common example of this is collections which have a default "Item" property.
In MATLAB, there is no concept of default property, so you must specify "Item" explicitly. Also, MATLAB does not allow properties to have input arguments, so "Item" is classified as a method of the collection.
For example, in Excel the "Columns" property of the "sheet" object is actually a range object (the actual type is listed as 1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range). In Visual Basic you can execute the command
col = sheets.Columns('A:C')
which is shorthand for
col = sheets.Columns.Item('A:C')
This is the syntax you need to use in MATLAB.