I\'m trying to write in a word document via VB.net and for this I\'m using contentControls in my Word Document but sometimes I have to delete a contentCont
I will give you some tips based on VBA which I hope you could easily convert to vb.net and your solution.
You need to cover complete range of ContentControl
including beginning and end of the object. You could do it in this way (VBA code for first CC in activedocument):
With ActiveDocument.ContentControls(1)
'just to make a presentation- let's select range to be deleted
ActiveDocument.Range(.Range.Start - 1, .Range.End + 2).Select
'and we delete selection
Selection.Delete
End With
Obviously you could combine .Select
and .Delete
lines into one to avoid selection in this way:
With.... and so on
ActiveDocument.Range(.Range.Start - 1, .Range.End + 2).Delete
End with