在图片上方插入形状的位置/放置问题

时间:2019-12-25 10:40:39

标签: vba ms-word

我试图在用户单击的光标位置的图片上方插入一个形状,我使用以下代码,但是有时会由于使用Select方法而出现放置问题。

无论如何,可以通过直接使用Word对象来避免这种情况。

  Sub CurosrXY_Pixels(Sel As Word.Selection)
  Dim shp As Word.Shape

Set shp = ActiveDocument.Shapes.AddShape(msoShapeRectangle, fcnXCoord(Sel), fcnYCoord(Sel), 20#, 16#, Sel.Range)
With shp.TextFrame.TextRange
    .Font.Name = "Arial"
    .Font.Size = 7
    .Font.Bold = False
    .Paragraphs.FirstLineIndent = 0
    .Paragraphs.RightIndent = -10
    .Paragraphs.LeftIndent = -10
    .Paragraphs.Alignment = wdAlignParagraphCenter
    .Text = 11
End With
shp.LockAspectRatio = msoCTrue
End Sub
  Function fcnXCoord(Sel As Word.Selection) As Double
 fcnXCoord = Sel.Information(wdHorizontalPositionRelativeToPage)
 End Function
  Function fcnYCoord(Sel As Word.Selection) As Double
  fcnYCoord = Sel.Information(wdVerticalPositionRelativeToPage)
     End Function

0 个答案:

没有答案