#1
|
|||
|
|||
Restrict editing based on background color of a table
Hello!
I have a table in my document where I am trying to restrict editing based on the background color of the table. Basically, if the background color is white (no shading), that's the only place I want people to be able to edit. How can I accomplish this in Word VBA? I've tried looking this up in a few other places, but I can only find advice for Excel VBA. Any help would be appreciated! |
#2
|
||||
|
||||
My recommendation would be to put Content Controls anywhere you want to be able to edit the contents and then apply document protection for forms. The real question is how to identify the 'white' cells. A 'white' cell could have no fill or a white fill via indexed color or RGB specification. It could also have color on a background or foreground setting so you might need to fiddle with this to identify target cells correctly.
The following code works on my test tables and shows how you could step through the code to help identify cells and add the CCs to the found cells. Code:
Sub SelectivelyAddCCs() Dim aCell As Cell, aCC As ContentControl, aTable As Table For Each aTable In ActiveDocument.Tables For Each aCell In aTable.Range.Cells aCell.Range.Select Debug.Print aCell.Shading.BackgroundPatternColorIndex If aCell.Shading.BackgroundPatternColorIndex = 0 Then If aCell.Range.ContentControls.Count = 0 Then ActiveDocument.ContentControls.Add Type:=wdContentControlText, Range:=aCell.Range End If End If Next aCell Next aTable End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Changing background colour in table based on value. | amandalee | Word Tables | 21 | 09-30-2020 03:13 PM |
Set color and background of special bullet in table cell | kkkwj | Word VBA | 2 | 05-08-2018 08:40 AM |
VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color | jc491 | Word VBA | 8 | 09-30-2015 06:10 AM |
How to remove background color in a table that isn't there but is there? | pintree3 | Word | 5 | 10-27-2014 10:23 AM |
Restrict Editing but Allow New Table Rows to be Added | weavie27 | Word Tables | 3 | 05-02-2014 03:11 PM |