I\'m trying to add a shape specifically a textbox.
I need to add it after all the contents I added through vba. I can\'t seem to figure how to do it since adding the sh
You can use the .RelativeVerticalPosition
to position the shape after you insert the shape. See this example
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
Followup
One other way is to find the cursor position and then insert the shape at that position. For example this will insert a shape where the cursor is. So in your original VBA code, you can use Selection.TypeParagraph
to move to the next line and then call the below code.
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