Consulting

Results 1 to 9 of 9

Thread: Reformatting Rich Content Control Contents

  1. #1
    VBAX Regular
    Joined
    Aug 2018
    Posts
    16
    Location

    Reformatting Rich Content Control Contents

    Hello,

    I have run into an interesting issue, at least to me. I have rich text content control boxes with text that is by default highlighted. Generally, as we walk through each CC we un-highlight the text, it is part of our process. Prior to creating and using the CCs we were able to triple click which activated a whole sentence and we could hit the un-highlight button to remove the highlight. Now that I am using the CCs, and only when there is a single sentence, the triple click will grab the whole sentence but the un-highlight button will not work. I have to click drag to select but not grab the entire contents of the CC in order to un-highlight. This appears to only be an issue when the CC is locked from being deleted, however the setting for locking the contents from being edited is NOT checked. Can you think of a reason that could be causing this? Or a possible workaround?

    I have attached an example for reference.
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    I my testing, the number of sentences or paragraphs within the content control makes no difference; selecting by triple-clicking prevents the highlight being removed.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Aug 2018
    Posts
    16
    Location
    Quote Originally Posted by macropod View Post
    I my testing, the number of sentences or paragraphs within the content control makes no difference; selecting by triple-clicking prevents the highlight being removed.
    Good to know it is not just me. What is odd is that if you triple-click and hit backspace or delete, it has no issue wiping out the text. It is perplexing why it would prevent formatting changes to the whole content control when selected this way, no?

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Perhaps it's a bug. It's been around since at least Word 2010, though.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    As your document is macro enabled, why not simply use a content control entry macro to unhighlight it when it is clicked? e.g. in the Thisdocument module:

    Option Explicit
    
    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
        ContentControl.Range.HighlightColorIndex = wdNoHighlight
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Yes, I've observed several oddities over the years with CCs and highlighting. However, it this case I think the issue is with how the triple click selection works (which could also be considered buggy). Before going forward, your sample document contain 2 content controls. One titled "Finding" containing the highlighted text nested in another CC (otherwise empty) also titled "Finding". I'm not sure if that is intentional or not.

    Using that document, triple click the text and run:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 9/29/2018
      MsgBox Selection.Range.Start & " " & Selection.Range.End
    lbl_Exit:
      Exit Sub
    End Sub
    The return is 0 and 125

    Now just select the text as you have done as a work around and run that code again. This time you get 2 and 125.

    While the selected range appears the same, clearly the triple click method is picking up a part of the CC that can't be edited.

    To add a bit of user control, I'll suggest an edit to Graham's method:

    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
      If MsgBox("Remove hightlight?", vbYesNo, "REFORMAT") = vbYes Then
        ContentControl.Range.HighlightColorIndex = wdNoHighlight
      End If
    End Sub
    Or if you want less intrusive control. Just click in the CC and run:

    Sub CCReview()
    Dim oCC As ContentControl
      On Error Resume Next
      For Each oCC In ActiveDocument.ContentControls
        If Selection.InRange(oCC.Range) Then
          oCC.Range.HighlightColorIndex = wdNoHighlight
          If oCC.Range.ContentControls.Count = 0 Then Exit For
        End If
      Next
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Regular
    Joined
    Aug 2018
    Posts
    16
    Location
    Quote Originally Posted by gmaxey View Post
    Yes, I've observed several oddities over the years with CCs and highlighting. However, it this case I think the issue is with how the triple click selection works (which could also be considered buggy). Before going forward, your sample document contain 2 content controls. One titled "Finding" containing the highlighted text nested in another CC (otherwise empty) also titled "Finding". I'm not sure if that is intentional or not.

    Using that document, triple click the text and run:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 9/29/2018
      MsgBox Selection.Range.Start & " " & Selection.Range.End
    lbl_Exit:
      Exit Sub
    End Sub
    The return is 0 and 125

    Now just select the text as you have done as a work around and run that code again. This time you get 2 and 125.

    While the selected range appears the same, clearly the triple click method is picking up a part of the CC that can't be edited.

    To add a bit of user control, I'll suggest an edit to Graham's method:

    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
      If MsgBox("Remove hightlight?", vbYesNo, "REFORMAT") = vbYes Then
        ContentControl.Range.HighlightColorIndex = wdNoHighlight
      End If
    End Sub
    Or if you want less intrusive control. Just click in the CC and run:

    Sub CCReview()
    Dim oCC As ContentControl
      On Error Resume Next
      For Each oCC In ActiveDocument.ContentControls
        If Selection.InRange(oCC.Range) Then
          oCC.Range.HighlightColorIndex = wdNoHighlight
          If oCC.Range.ContentControls.Count = 0 Then Exit For
        End If
      Next
    End Sub

    Greg, out of curiosity, I have been trying to add a precheck to the "User Control" code you suggested where IF the text is already unhighlighted exit the routine and not prompt the user. Is this possible and am I on the right path? So far I have been unable to get this to work.

    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
      If ContentControl.Range.HighlightColorIndex = wdNoHighlight Then End Sub
      Else
      If MsgBox("Remove hightlight?", vbYesNo, "Reformat Text?") = vbYes Then
        ContentControl.Range.HighlightColorIndex = wdNoHighlight
      End If
      End If
    End Sub
    Last edited by tgamekh; 10-06-2018 at 07:39 AM.

  8. #8
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Close:

    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
      If ContentControl.Range.HighlightColorIndex = wdNoHighlight Then
        Exit Sub
      Else
        If MsgBox("Remove hightlight?", vbYesNo, "Reformat Text?") = vbYes Then
          ContentControl.Range.HighlightColorIndex = wdNoHighlight
        End If
      End If
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  9. #9
    VBAX Regular
    Joined
    Aug 2018
    Posts
    16
    Location
    Again, I thank you. Have a great day sir.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •