I aim to replace a certain text in a ms word document with a textbox. This textbox needs to have the replaced text in it. The textbox should appear at the same position like the replaced text and the following content must wrap around the textbox.
With the following code I can accomplish the replacement of the text with a textbox and with the replaced text in the textbox, but the textbox is always at the same place.
What I need now, is the possibility to get the position of a found text to use it for the textbox to replace the found text. :)
My code snippet:
positionLeft = 50 /* here I need the left position of the found text */
positionTop = 50 /* and here the top position */
With ActiveDocument.Range.find
.Forward = True
.Wrap = wdFindStop
.Text = TextToReplace
.Execute
If .Found = True Then
Dim Box As Shape
Set Box = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, positionToLeft, positionToRight, 100, 100)
Box.TextFrame.textRange.Text = TextToReplace
.Parent = ""
End If
End With
Is it even possible to get the absolute left and top position of a text in the word document? And if yes, how can i get this done?