簡體   English   中英

使用VBA在MS Word上的內聯形狀下方添加文本框

[英]Add a TextBox below an Inline Shape on MS Word using VBA

我正在嘗試使用內聯文字換行在所選圖像下方插入一個文本框,並將其放置在圖像的左下方。 我使用下面的代碼沒有太大的成功。 我不太確定要使用ShapeRange還是InlineShape。 有指針嗎?

Dim shp As Object
'Set shp = Selection.ShapeRange(1)
'Set rng = shp.Anchor
Set shp = Selection.InlineShapes(1)
Set rng = shp.Range

With ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=shp.Left, Top:=(shp.Top + shp.Height), Width:=shp.Width / 3, Height:=shp.Height / 6, Anchor:=rng)
    .TextFrame.TextRange.Font.Size = 14
    .TextFrame.TextRange.Font.Color = RGB(186, 14, 29)
    .TextFrame.TextRange.Font.Name = "Sabon MT"
    .TextFrame.TextRange = "T"
End With

我設法找到一種從此處獲取形狀坐標的解決方案: http : //www.vbaexpress.com/forum/archive/index.php/t-48831.html

這是我的代碼:

Sub AddTextBox

    Set shp = Selection.InlineShapes(1)
    Set rng = shp.Range       
    Set tb = ActiveDocument.Shapes.AddTextbox(1, fcnXCoord, fcnYCoord + shp.Height, shp.Width, shp.Height / 6)

End Sub

Function fcnXCoord() As Double
    fcnXCoord = Selection.Information(wdHorizontalPositionRelativeToPage)
End Function

Function fcnYCoord() As Double
    fcnYCoord = Selection.Information(wdVerticalPositionRelativeToPage)
End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM