user1821321
user1821321

Reputation: 33

Powerpoint VBA table & object alignment

I have a macro which generates a table with 3 columns and a dynamic number of rows. The 3rd column is labeled "Trend" and the macro creates an arrow pointing up, down, or to the left but these arrows are not grouped with the table.

In the third column the macro inserts "-" vertically and horizontally centered in the table cell, just so I know the center and i have to realign the arrows once the macro has run.

Is there code to determine x,y coordinates of the "-" or to determine row hieghts to center the arrow with in each cell in the 3rd column?? The row height is dynamic depending on the amount of text contained in the other cells from the same row.

Upvotes: 0

Views: 8416

Answers (3)

David Zemens
David Zemens

Reputation: 53623

Instead of using the "-" character as a placeholder, over which you will lay a Shape arrow, you could simply use a special character.

Assume that tblCell has been dimensioned as a Shape and has been set to a particular cell's .Shape, then you can do:

tblCell.TextFrame.TextRange.Text = ChrW(&H25B2) 'Up arrow

or:

tblCell.TextFrame.TextRange.Text = ChrW(&H25BC) 'Down arrow

And then to align it:

tblCell.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter

Upvotes: 0

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

Since you're only using the "-" as a positioning aid, wouldn't it be simpler to add the shape you want directly?

Simple example, assuming you've selected a table on slide 1:

Dim oSh As Shape
Dim oNewSh As Shape
Set oSh = ActiveWindow.Selection.ShapeRange(1).Table.Cell(1, 2).Shape
Set oNewSh = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeSmileyFace, oSh.Left, oSh.Top, oSh.Width, oSh.Height)

This fills the cell with a smiley; instead, you'd want to work with the coordinates of oSh (which represents the rectangular shape of the cell) and do whatever math is needed to center your shape within it.

Upvotes: 1

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19067

Assuming there is only one table shape on slide 'one' with 2x2 cells dimension, and your hyphen is in cell(2,2), than you have to add two parameters:

Sub test()

Dim A, B
     A = ActivePresentation.Slides(1).Shapes(1).Table.Cell(2,2).Shape.TextFrame.TextRange.Lines(1).BoundTop
     B = ActivePresentation.Slides(1).Shapes(1).Top

Debug.Print A + B


ActivePresentation.Slides(1).Shapes.AddShape msoShapeRectangle, 100, A + B, 20, 20
End Sub

where A+B is approx. what you are looking for.

Upvotes: 0

Related Questions