#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
So you have a table-> ContentControl -> Cell and I want to highlight that Cell.
The function I wrote knows when it is in a table and when it is in a ContentControl but when there is a table and a Cell it gets that bug. I think there is a mistake with Selection |
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 |
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 |
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 |