Powerpoint VBA 表格和对象对齐

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15638681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:15:50  来源:igfitidea点击:

Powerpoint VBA table & object alignment

vbapowerpointpowerpoint-vba

提问by user1821321

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.

我有一个宏,它生成一个包含 3 列和动态行数的表。第三列标记为“趋势”,宏创建一个向上、向下或向左的箭头,但这些箭头未与表格分组。

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.

是否有代码来确定“-”的 x、y 坐标或确定行高以将箭头与第三列中的每个单元格居中?行高是动态的,具体取决于同一行中其他单元格中包含的文本量。

回答by Steve Rindsberg

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:

简单示例,假设您在幻灯片 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.

这会用笑脸填充单元格;相反,您希望使用 oSh 的坐标(代表单元格的矩形形状)并进行任何需要的数学运算以将您的形状居中。

回答by David Zemens

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

Shape您可以简单地使用特殊字符,而不是使用“-”字符作为占位符,您将在其上放置一个箭头。

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

假设tblCell已将尺寸标注为 Shape 并已设置为特定单元格的.Shape,那么您可以执行以下操作:

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

回答by Kazimierz Jawor

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:

假设幻灯片“一”上只有一个表格形状,单元格尺寸为 2x2,并且您的连字符在单元格(2,2)中,那么您必须添加两个参数:

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.

其中 A+B 是大约。你在找什么。