When there is only one shape to create, the presentation does not matter much in my view and you can make it as pretty as you want. It is when you have multiple shapes and and you need to keep consistency but also allow for variation that you want to put function over form. In that case you might want to use something like this:
Code: Select all
xl := ComObjActive("Excel.application")
xl.ActiveSheet.Shapes.AddShape(1,10, 10, 200, 100)
xl.ActiveSheet.Shapes.AddShape(1,10, 160, 200, 100)
xl.ActiveSheet.Shapes.AddShape(1,10, 310, 200, 100)
for shape in xl.ActiveSheet.Shapes
{
shape.Textframe.Characters.Text := "This is a rectangle number " a_index
shape.TextFrame.HorizontalAlignment := -4108 ; -4108 Center; -4131 Left; -4152 Right; -4130 Justify
shape.TextFrame.VerticalAlignment := -4108
shape.Fill.ForeColor.RGB := 13494510 ; http://cloford.com/resources/colours/500col.htm
shape.Line.ForeColor.RGB := 11651277
shape.TextFrame.Characters.Font.Color := 35723
shape.TextFrame.Characters.Font.Size := 24
}
When it comes to assigning variables to the various Excel parameters (i.e. msoShapeRectangle := 1, xlHAlignCenter := -4108, xlVAlignCenter := -4108), I do not do it, and don't see the use of it. If I need to remind myself of the different values that I might want to use, I list them in a comment like I did above with the HorizontalAlignment. That's much more useful IMHO.