Codes (activex..) for Copy graphs (figure) from Matlab to Excel

2 ビュー (過去 30 日間)
Ginés Aníbal
Ginés Aníbal 2022 年 9 月 18 日
移動済み: Image Analyst 2022 年 9 月 18 日
"Dest" (or "Dst") means destination object
a) Once ArchDest, HojaDest, were defined, in a 2016 script I used;
exc=actxserver('Excel.Application');
winopen(ArchDest);
SheetD = get(exc.Worksheets,'Item',HojaDest);
invoke(SheetD,'Activate');
In the third code it tells me: "Dot indexing is not supported for variables of this type", now.
I haven't been able to find the cause. Excel file (Office 2019) opens correctly, but the script stops before select corresponding Sheet (unprotected). What should I correct?
b) Selecting sheet manually and from Command Window, then I had other problem choosing the Range in following codes (used in 2016). Previously I defined RanDstPlot:
ExActS = exc.ActiveSheet ;
ExActRa = get(ExActS,'Range',RanDstPlot);
%error "too many arguments".
(Here I see that this has changed now).
But I would be satisfied to get through step a) for now.-
Thank you very much!!!!

採用された回答

Image Analyst
Image Analyst 2022 年 9 月 18 日
@Ginés Aníbal See my attached demo and the function PasteFigureIntoExcel.
Also see my other demo for using ActiveX to paste into Word. Excel should be pretty similar.
Adapt as needed.
  1 件のコメント
Ginés Aníbal
Ginés Aníbal 2022 年 9 月 18 日
移動済み: Image Analyst 2022 年 9 月 18 日
OK Thanks again!!! I see yours demos, now,

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

その他の回答 (1 件)

dpb
dpb 2022 年 9 月 18 日
編集済み: dpb 2022 年 9 月 18 日
I can't believe this ever worked -- there's been no file associated with the COM object in this code by itself.
Unless the connection had been created elsewhere before and a valid object still existed in the workspace when the code was run, the .Worksheets property is going to return an error because there's no ActiveWorkbook associated with the COM engine.
>> Excel = actxserver('excel.application')
Excel =
COM.excel_application
>> excelFullFileName=fullfile(cd,'Data.xlsx'); % an existing file
>> winopen(excelFullFileName)
>> Excel.Worksheets
Error: Object returned error code: 0x800A03EC
>>
There's nothing associated with the Excel COM server at the moment...to see this, try
>> Excel.ActiveWorkbook
ans =
[]
>>
There is no .ActiveWorkbook that this instance of the COM server knows anything about even though the workbook referred to by excelFullFileName is open...COM just doesn't work like that; never has.
You've got to open the workbook to get a handle/object...
>> workbook = Excel.Workbooks.Open(excelFullFileName)
workbook =
Interface.000208DA_0000_0000_C000_000000000046
>> workbook.Worksheets
ans =
Interface.000208D7_0000_0000_C000_000000000046
>> ans.Item(1).Name
ans =
'List1'
>>
and carry on from there with whatever it is that is to be done.
As illustrated, the above uses "dot" notation, it will and does work with valid Excel COM objects, but your code doesn't create those.
The above was run in R2020b but it's been the same scenario "since forever"...
  1 件のコメント
Ginés Aníbal
Ginés Aníbal 2022 年 9 月 18 日
Thank you very much, and double for your answer on Sunday!!!
I will take into account all your conceptual comments and details.
In the query I only transcribed the 4 fist codes from activex (until the error) of that part of the script... but that way I had fixed it then. Best regards!!

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

カテゴリ

Help Center および File ExchangeActiveX についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by