PDA

View Full Version : [SOLVED:] Reformatting Rich Content Control Contents



tgamekh
09-28-2018, 01:01 PM
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.

macropod
09-28-2018, 03:25 PM
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.

tgamekh
09-28-2018, 03:33 PM
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?

macropod
09-28-2018, 03:41 PM
Perhaps it's a bug. It's been around since at least Word 2010, though.

gmayor
09-28-2018, 08:15 PM
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

gmaxey
09-29-2018, 06:41 AM
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

tgamekh
10-06-2018, 06:53 AM
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

gmaxey
10-06-2018, 07:59 AM
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

tgamekh
10-06-2018, 08:02 AM
Again, I thank you. Have a great day sir.