View Single Post
 
Old 07-26-2021, 05:23 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Once you have added the CCs you can turn on the Restrict Editing for forms (via the Developer Tab). You will be able to find code on this forum to do this but you can easily record this step to see sample code.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote