How to omit a parameter passed to Excel via COM?

3 ビュー (過去 30 日間)
John B.
John B. 2022 年 4 月 3 日
コメント済み: John B. 2022 年 4 月 7 日
I want to create a table (database) in an Excel file. The Excel file was created via Matlab writetable function, but I want to set the database inside of the Excel file after I create it. (The table option in Excel puts headings onto data columns and adds a means to sort items). I ran a macro so that I can see what VB code will set the table inside Excel. This is what I get in Excel:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$F$6"), , xlYes).Name = _
"Table1"
I form the corresponding Matlab code:
wb.ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$F$6"),,xlYes).Name = 'Table1';
However, Matlab gives me an error message:
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
It appears Matlab doesn't like the " ,, " in the parameter list. The Microsoft documentation says this parameter is for the LinkSource, and says this in their documention:
....Invalid if SourceType is xlSrcRange, and will return an error if not omitted.
Hence I conclude that I want to omit the parameter per Microsoft, and make it 'blank', but I don't see how to do that and prevent the error from Matlab. I've tried 0, a no character string ( '' ) etc.. and nothing seems to work.
Thanks for your time.

回答 (1 件)

Image Analyst
Image Analyst 2022 年 4 月 3 日
Sometimes the later arguments are not needed. What if you omit the ', , xlYes' altogether?
  2 件のコメント
John B.
John B. 2022 年 4 月 3 日
Omitting ', , xlYes' did not work. If I turn the two commas into one, from: , , to: , that doesn't work either. thanks, John
John B.
John B. 2022 年 4 月 7 日
The answer, which now seems simple, is to use an empty array: [].
So this will work:
wb.ActiveSheet.ListObjects.Add(xlSrcRange,wsRange,[],xlYes).Name = 'Table3';
Further documentation is available here:
https://www.mathworks.com/help/matlab/matlab_external/using-methods.html#f89811

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeUse COM Objects in MATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by