Indentify deleted content control in BeforeDelete event RRS feed

  • Question

  • I am developing a MS Word Add-in where Content Control text is locked and is changed automatically based on their sequence in document.

    On Content Control delete event, I need to iterate on each control and change it's Range Text. I am able to do it but the problem is the Content Contorl which is just deleted is also part of ActiveDocument.ContentControls and when the event tries to unlock it and change the Range.Text, it throws run time error 5825 saying "Object has been deleted"

    Below is the my Document_ContentControlBeforeDelete event.
    Private Sub Document_ContentControlBeforeDelete(ByVal OldContentControl As ContentControl, ByVal InUndoRedo As Boolean)
        Dim ContentCtrl As ContentControl
        Dim Counter As Long
        Counter = 1
        For Each ContentCtrl In ActiveDocument.ContentControls
            ContentCtrl.LockContents = False
            ContentCtrl.Range.Text = Counter
            ContentCtrl.LockContents = True
            Counter = Counter + 1
    End Sub

    Is there any way to identify though code that a Content Control has been deleted so I can skip it in my loop.



    • Edited by avi1001 Thursday, February 19, 2015 7:06 PM
    Thursday, February 19, 2015 7:04 PM