none
Removing the default paragraph marker immediately after rich text content control RRS feed

  • Question

  • Hello, 

       I am inserting a rich text content control from a server into a word document with an add-in. The entire document is locked except for a section where I insert section breaks around this RTCC so that the user can format the text as theyd like.

    The issue I am running into is that due to the default paragraph marker next to the RTCC, the user can click outside of the RTCC and enter text, where they should only be inside the RTCC. When I am in the document I can delete it and the section break "goes into" the RTCC, which is fine. 

    Is there a way to programmatically remove the default paragraph marker to so that the user cannot click outside the RTCC?


    • Edited by Luke415 Friday, October 30, 2015 6:09 PM add pic
    Friday, October 30, 2015 6:07 PM

All replies

  • There is no need to insert a paragraph break along with a content control, so this issue has to do with your addin's coding, not a default behaviour in Word.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, October 30, 2015 8:55 PM
  • Is there a way to insert a section break programmatically into a rich text content control then?
    Monday, November 2, 2015 5:37 PM
  • Sure:

    Sub Demo1()
    Dim CCtrl As ContentControl, Rng As Range
    With ActiveDocument
      Set Rng = .Paragraphs.Last.Previous.Range
      With Rng
        .Collapse Direction:=wdCollapseStart
        .InsertBreak Type:=wdSectionBreakContinuous
        .End = .End - 1
        .Collapse Direction:=wdCollapseStart
      End With
      Set CCtrl = .ContentControls.Add(Type:=wdContentControlRichText, Range:=Rng)
      With CCtrl
        .LockContentControl = True
        .Range.Text = "hello world"
      End With
    End With
    End Sub

    That said, it would probably be better to insert the Section break after the content control:

    Sub Demo2()
    Dim CCtrl As ContentControl, Rng As Range
    With ActiveDocument
      Set Rng = .Paragraphs.Last.Previous.Range
      With Rng
        .InsertBefore Chr(32)
        .Collapse Direction:=wdCollapseStart
      End With
      Set CCtrl = .ContentControls.Add(Type:=wdContentControlRichText, Range:=Rng)
      With CCtrl
        .LockContentControl = True
        With .Range
          .Text = "hello world"
          With .Characters.Last.Next.Next
            .InsertBreak Type:=wdSectionBreakContinuous
            .Delete
          End With
        End With
      End With
    End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, November 2, 2015 8:36 PM
  • This would insert the section break after the RTCC but before the paragraph marker that is outside the RTCC?
    Monday, November 2, 2015 10:04 PM
  • The first one inserts the Section break into the content control. The second one inserts it immediately after (i.e. before any other content, whether text, paragraph breaks, etc.).

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, November 2, 2015 10:12 PM