How to order a Shapes object with actxserver for Excel?
Show older comments
I am trying to send an image I input into an Excel file to the back of the Shapes object. I have tried two different methods.
Method 1: Selection and Send to Back
objExcel = actxserver('Excel.Application');
objExcel.Workbooks.Open(excelFileName);
myshapes = objExcel.ActiveSheet.Shapes;
N = myshapes.Count;
ShapeToBack = myshapes.Item(N);
ShapeToBack.SendToBack();
The problem is that the .SendToBack function is not recognized. I did test out the Send To Back option in Excel and this did reorder the image in the myshapes. I was hoping to do that programatically, but I can't find a way to do it in MATLAB.
Method 2: Copy Delete and Paste
objExcel = actxserver('Excel.Application');
objExcel.Workbooks.Open(excelFileName);
myshapes = objExcel.ActiveSheet.Shapes;
N = myshapes.Count;
for j = 1:N-1
ShapeToCopy = myshapes.Item(j);
ShapeToCopy.Copy();
myshapes.Item(j).Delete
objExcel.ActiveSheet.Paste();
end
The problem here is that for some reason this doesn't change the order. The shape object at the end of myshapes stays at the end.
2 Comments
dpb
on 23 Aug 2024
The problem isn't in MATLAB, there's no SendtoBack method for the Excel shapes object -- see <Excel shapes VBA methods>. There is a <ShapeRrange object ZOrder method>, however.
I've done quite a lot w/ ActiveX in Excel from MATLAB but have never used shapes in Excel so absolutely no experience in controlling them, but if it's in the VBA doc, you can (eventually) find a way from MATLAB. You have to remember that MATLAB doesn't know anything about VBA syntax, however, so much of the higher level coding in the examples won't work directly.
Cameron Sellers
on 26 Aug 2024
Accepted Answer
More Answers (0)
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!