Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-02-2020, 08:28 AM
keine keine is offline Highlight a Cell which is in a ContentControl which is in a table Windows 7 64bit Highlight a Cell which is in a ContentControl which is in a table Office 2016
Novice
Highlight a Cell which is in a ContentControl which is in a table
 
Join Date: Jan 2020
Posts: 2
keine is on a distinguished road
Question Highlight a Cell which is in a ContentControl which is in a table

I have a problem.
So, when I am in a cell then I gonna make a function that highlights it(cellColor()) and when I am in a ContenControl I also have a function which highlights(toggleYellow) it. So there is a simple If-function.(checkTableCC), which looks if you are in a ContentControl or in a Cell. So there is no problem.



But when there is a table and in that table there is ContentControl and in the ContentControl there is again a new table the If-Function does not work when I want to highlight the cell of the table which is in the ContentControl and which is in another table and I get an error 4641 The HighlightColor statement is currently disabled. I tried some things out but I cannot get the double check of the function. Maybe someone can help.



The error appears here: Selection.Cells(1).Range.HighlightColorIndex = wdBrightGreen

So I want to highlight the "Hey" in that Cell in the image.
Here is my code so far which I did with the help of you guys. Thank you again:

Code:
'CC function
Function IsSelectionInCC(sel As Word.Selection) As Word.ContentControl
    Dim rng As Word.Range
    Dim doc As Word.Document
    Dim nrCC As Long
    Dim cc As Word.ContentControl
    Dim InCC As Boolean

    InCC = False
    Set rng = sel.Range
    Set doc = rng.Parent
    rng.Start = rng.Document.Content.Start
    nrCC = rng.ContentControls.Count
    If nrCC > 0 Then
        If sel.InRange(doc.ContentControls(nrCC).Range) Then
            InCC = True
            Set cc = doc.ContentControls(nrCC)
        Else
            sel.MoveEnd wdCharacter, 1
            If Len(sel) = 0 Then
                InCC = True
                Set cc = doc.ContentControls(nrCC)
            End If
        End If
    End If
    Set IsSelectionInCC = cc
End Function


'Highlight ContentControl[![enter image description here][1]][1]
Sub toggleYellow()
Dim rng As Word.Range
Dim cc As Word.ContentControl

    Set cc = IsSelectionInCC(Selection)
    If Not cc Is Nothing Then
        Set rng = cc.Range
        If rng.HighlightColorIndex = wdNoHighlight Then
            rng.HighlightColorIndex = wdYellow
        Else
            rng.HighlightColorIndex = wdNoHighlight
        End If
    End If
End Sub


'Highlight cell
Sub cellColor()

Selection.Collapse Direction:=wdCollapseStart
If Not Selection.Information(wdWithInTable) Then
    MsgBox "Nur in einer Tabelle funktioniert dieses Makro."
    Exit Sub
End If

If Selection.Cells(1).Range.HighlightColorIndex = wdNoHighlight Then
    Selection.Cells(1).Range.HighlightColorIndex = wdYellow
Else
    Selection.Cells(1).Range.HighlightColorIndex = wdNoHighlight
End If

Exit Sub
End Sub


'Check If you are in a CC or in a Cell
Sub checkTableCC()

Dim rng As Word.Range
Dim cc As Word.ContentControl

Set cc = IsSelectionInCC(Selection)
If Not cc Is Nothing Then
    toggleYellow
Else
    cellColor
End If
End Sub
Reply With Quote
 

Tags
cell, content control, highlight



Similar Threads
Thread Thread Starter Forum Replies Last Post
contentcontrol in a word table lacja Word VBA 1 08-22-2018 02:25 PM
Highlight a Cell which is in a ContentControl which is in a table Using VBA to Compare and Highlight words in a Word Table's Row/Cell KeithLee22 Word VBA 2 11-11-2015 03:37 PM
Adding ContentControl to a table milena Word VBA 2 04-20-2015 01:04 AM
Highlight a Cell which is in a ContentControl which is in a table How to highlight the row based on cell value? Learner7 Excel 1 12-11-2011 02:28 AM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft