none
Detecting if cursor is inside Content Control RRS feed

  • Question

  • I am trying to add a bookmark programmatically.  If the cursor is inside a content control, I get an error.  I've used while selection.range.parentcontentcontrol.title <> "", selection.moveleft wdcharacter, 1, but as soon as I am no longer in a content control I get an error.  How can I code to determine if I am in a content control or not and act accordingly.  There does not seem to be an informaiton property, like if inside a table.  I'm sure it must be something to do with InRange, but haven't found the answer. 

    Thank you.

    Wednesday, March 28, 2012 8:25 PM

Answers

  • Hi,

    I think that something like

    Public Function SelectionInContentControl() As Boolean
       Dim bResult As Boolean
       Dim objCC As ContentControl
       
       bResult = False
       For Each objCC In ActiveDocument.ContentControls
          If Selection.InRange(objCC.Range) Then bResult = True: Exit For
       Next
       SelectionInContentControl = bResult
    
    End Function

    should accomplish the task.

    By, Lauro

    Thursday, March 29, 2012 7:38 PM

All replies