How can I find a textbox (by the text), remove it and its parent picture canvas, and insert an image where the textbox originally is? Right now, my code removes only the textbox but not the parent picture canvas. If I do builder.currentnode.parent.remove(), it removes the textbox and the image I inserted. Is there a better way to do this?
For Each s As Words.Section In doc.Sections
For Each p As Words.Paragraph In s.Body.Paragraphs
For i As Integer = p.ChildNodes.Count - 1 To 0 Step -1
Dim cNode As Words.Node = p.ChildNodes(i)
If cNode.NodeType = Words.NodeType.Shape Then
Dim sh As Words.Shape = DirectCast(cNode, Words.Shape)
If sh.Range.Text.ToLower.IndexOf(tbName) > 0 Then
builder.MoveTo(cNode)
builder.CurrentNode.Remove()
builder.InsertImage(GetImage())
builder.MoveTo(cNode)
builder.CurrentNode.Remove()
Exit For
End If
End If
Next
Next
Next