在文档末尾添加形状

在文档末尾添加形状

本文介绍了在文档末尾添加形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个专门用于文本框的形状.

I'm trying to add a shape specifically a textbox.

我需要在通过vba添加的所有内容之后添加它.我似乎无法弄清楚该如何做,因为添加形状需要精确测量Left和Top参数.

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 shape needs the exact measurement of the Left and Top parameters.

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放置形状.看到这个例子

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

跟进

另一种方法是找到光标位置,然后在该位置插入形状.例如,这将在光标所在的位置插入一个形状.因此,在原始VBA代码中,您可以使用Selection.TypeParagraph移至下一行,然后调用以下代码.

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

这篇关于在文档末尾添加形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:46