Vba 在文档末尾添加形状

Vba 在文档末尾添加形状,vba,ms-word,Vba,Ms Word,我正在尝试添加一个特定于文本框的形状 我需要在我通过vba添加的所有内容之后添加它。我似乎不知道怎么做,因为添加形状需要精确测量左侧和顶部参数 Dim shpActual Dim pos, PtsToInches set shpActual = Selection.Shapes.AddTextbox(msoTextOrientationHorizontal, 92, PtsToInches, 437.4, 69) pos = Selection.Range.Informatio(wdVer

我正在尝试添加一个特定于文本框的形状

我需要在我通过vba添加的所有内容之后添加它。我似乎不知道怎么做,因为添加形状需要精确测量左侧和顶部参数

Dim shpActual 
Dim pos, PtsToInches 
set shpActual = Selection.Shapes.AddTextbox(msoTextOrientationHorizontal, 92, PtsToInches, 437.4, 69) 
pos = Selection.Range.Informatio(wdVerticalPositionRelativeToPage) 
PtsToInches = pos / 72

插入形状后,可以使用
.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.typeparation
移动到下一行,然后调用下面的代码

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

谢谢但文件的页数各不相同。形状仅放在第一页的末尾。它不起作用..:(在“Set-objsShape”行中显示“类型不匹配”。我试图在没有类型的情况下声明objsShape,但现在错误出现在“Object不支持此属性或方法”中。“pos=Selection.Information(wdVerticalPositionRelativeToPage)中)“我在发布之前测试了代码。你能分享你尝试过的代码吗?Dim shpActual Dim pos,PtsToInches set shpActual=Selection.Shapes.AddTextbox(msoTextOrientationHorizontal,92,PtsToInches,437.4,69)pos=Selection.Range.Informatio(wdVerticalPositionRelativeToPage)PtsToInches=pos/72