Add Shape at the end of the document

后端 未结 1 1439
执念已碎
执念已碎 2021-01-23 15:54

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

相关标签:
1条回答
  • 2021-01-23 16:03

    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
    
    0 讨论(0)
提交回复
热议问题