Select Two Images In Excel Using ActiveX
3 ビュー (過去 30 日間)
古いコメントを表示
I have an Excel Workbook which contains two pictures in it. The picture names are "Picture 2" & "Picture 3".
I am able to select either picture by itself like so
E = actxserver('Excel.Application'); % start COM server
E.Visible=1; % makes visible
E.Workbooks.Open('myWorkbook.xlsx'); % opens file
E.ActiveSheet.Shapes.('Picture 2').Select % selects Picture 2
or alternatively
E.ActiveSheet.Shapes.Item(2).Select
I cannot figure out how to select both at once. I tried several different ways but none of them work
E.ActiveSheet.Shapes.('Picture 2','Picture 3').Select
E.ActiveSheet.Shapes.({'Picture 2','Picture 3'}).Select
E.ActiveSheet.Shapes.("Picture 2","Picture 3").Select
E.ActiveSheet.Shapes.(["Picture 2","Picture 3"]).Select
I recorded a macro in Excel selecting the two pictures...
ActiveSheet.Shapes.Range(Array("Picture 2", "Picture 3")).Select
...and notice that the two picture names are grouped in the Array function.
Thanks in advance for any help.
Mike
0 件のコメント
回答 (1 件)
Prathamesh
2023 年 7 月 21 日
Hi,
I understand that you want to select two images from excel.
You can use the “cellfun()” function to create “imagenamecell” object and use it to select multiple images.
Excel = actxserver('Excel.Application');
fullFileName = 'C:\path\to\workbook.xlsx';
ExcelWorkbook = Excel.Workbooks.Open(fullFileName);
oSheet = ExcelWorkbook.Sheets.Item(1);
Shapes = oSheet.Shapes;
imageNames = {'Picture 2', 'Picture 3'};
imageNamesCell = cellfun(@(x) [oSheet.Name, '!', x], imageNames, 'UniformOutput', false);
Shapes.Select(imageNamesCell);
Alternatively, you can use a for loop
Excel = actxserver('Excel.Application');
fullFileName = 'C:\path\to\workbook.xlsx';
ExcelWorkbook = Excel.Workbooks.Open(fullFileName);
oSheet = ExcelWorkbook.Sheets.Item(1);
Shapes = oSheet.Shapes;
imageNames = {'Picture 2', 'Picture 3'};
for i = 1:numel(imageNames)
shapeName = imageNames{i};
shape = Shapes.Item(shapeName);
shape.Select;
end
I hope this resolves your issue.
参考
カテゴリ
Help Center および File Exchange で ActiveX についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!