1

図形、具体的にはテキストボックスを追加しようとしています。

vbaで追加したすべてのコンテンツの後に追加する必要があります。形状を追加するには、LeftパラメーターとTopパラメーターを正確に測定する必要があるため、その方法がわかりません。

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

1 に答える 1

1

図形を挿入した後、 を使用し.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

ファローアップ

もう 1 つの方法は、カーソル位置を見つけて、その位置に図形を挿入することです。たとえば、これはカーソルがある場所に形状を挿入します。したがって、元の 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
于 2013-01-18T09:55:26.600 に答える