How to order a Shapes object with actxserver for Excel?
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.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. 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. actxserver, excel shapes, excel objects, excel MATLAB Answers — New Questions