(Solved) – Position /Placement issue to insert shape above the picture

  • by

I am trying to insert a shape above picture at the cursor position where the user click, I use the following code, but sometimes there is a placement issue because of the use of the Select method.

Is there anyway to avoid this by working directly with the Word objects.

  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

Leave a Reply

Your email address will not be published. Required fields are marked *