Consulting

Results 1 to 5 of 5

Thread: Highlight Blanks In A Table & Grey Out Table Cells Given "Yes" in Content Control

  1. #1

    Highlight Blanks In A Table & Grey Out Table Cells Given "Yes" in Content Control

    I would like to highlight cells yellow when they are blank. Once a user fills them out, the yellow highlight is removed.

    Secondly, I would like to grey out certain fields based on whether a content control field is answered "Yes" or "No".

    picture_sample.jpg
    Last edited by TimJones; 08-30-2018 at 12:36 PM. Reason: Added Picture

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Put this in the ThisDocument module:

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
      If Not ContentControl.ShowingPlaceholderText Then
        ContentControl.Range.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
      Else
        ContentControl.Range.Cells(1).Shading.BackgroundPatternColor = wdColorYellow
      End If
      Select Case ContentControl.Title
        Case "YesNo1"
          If ContentControl.Range.Text = "Yes" Then
            'Do this
          Else
            'Do that
          End If
      End Select
    End Sub
    Tag you YesNo CC "YesNo1" "YesNo2" etc.

    What do you mean "grey out fields"
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Thank you, Greg.

    By "grey out", I just mean a grey background in a table cell. Also, will the yellow highlight work in a table without a content control? It's just a basic table and I would like the empty/blank cells to be highlighted. Picture below might better explain.

    picture_sample.jpg

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Tim,

    You could run a procedure manually to highlight all empty cells in a table (or selective cells), but there is no event triggers from just filling in a table cell.

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
      On Error Resume Next
      
      Select Case ContentControl.Title
        Case "YesNo1"
          If ContentControl.Range.Text = "Yes" Then
            ActiveDocument.Tables(1).Cell(2, 2).Range.Shading.BackgroundPatternColor = wdColorGray50
          Else
             ActiveDocument.Tables(1).Cell(2, 2).Range.Shading.BackgroundPatternColor = wdColorAutomatic
          End If
      End Select
    End Sub
    
    Sub ShadedCells()
    Dim oCell As Cell
      For Each oCell In ActiveDocument.Tables(1).Range.Cells
        If Len(oCell.Range.Text) = 2 Then
          oCell.Range.Shading.BackgroundPatternColor = wdColorYellow
        Else
          oCell.Range.Shading.BackgroundPatternColor = wdColorAutomatic
        End If
      Next oCell
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    Thank you, Greg. Got the greying out to work.

    Can the greying out be locked (to prevent entering anything) if I use incorporate Legacy Form fields into the table?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •