.RelativeVerticalPosition
插入形状后,您可以使用来定位形状。看这个例子
Sub Sample()
Dim objShape As Shape
Set objShape = ActiveDocument.Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, _
Left:=10, Top:=10, Width:=80, Height:=80)
With objShape
.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
.RelativeVerticalPosition = wdRelativeVerticalPositionBottomMarginArea
.Left = wdShapeCenter
.Top = wdShapeTop
End With
End Sub
跟进
另一种方法是找到光标位置,然后在该位置插入形状。例如,这将在光标所在的位置插入一个形状。因此,在您原来的 VBA 代码中,您可以使用Selection.TypeParagraph
移动到下一行,然后调用下面的代码。
Sub Sample()
Dim objShape As Shape
Dim pos, PtsToInches
Set objShape = ActiveDocument.Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, _
Left:=10, Top:=10, Width:=80, Height:=80)
pos = Selection.Information(wdVerticalPositionRelativeToPage)
PtsToInches = pos / 72
With objShape
.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
.Left = wdShapeCenter
.Top = PtsToInches
End With
End Sub