Change Word Table Cell Color When a Checkbox Is Selected
Question details
Change the background color of a Word table cell according to its checkbox state.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A document contains a table with many checkboxes, and each checkbox should control the shading of its cell.
- Observed behavior
- The required method depends on whether the checkboxes are content controls, legacy form fields, or ActiveX controls.
Identify the checkbox type on Word’s Developer tab: content controls, legacy form fields, and ActiveX controls require different VBA handling. The example below is for checkbox content controls, with one checkbox per cell, in desktop Word.
Use a VBA event to shade cells with checkbox content controls
Use this method when each table cell contains one checkbox content control. The shading updates when you leave the control.
Word does not offer spreadsheet-style conditional formatting for table checkboxes. This document event applies yellow shading to a checked control’s cell and automatic shading when it is unchecked; it does not preserve a previous custom cell color.
In Word, select File > Save As and choose Word Macro-Enabled Document (*.docm).
Select Developer > Visual Basic. In the project window, expand your document’s project and open ThisDocument. If Developer is hidden, enable it in Word’s ribbon settings.
Paste this code into ThisDocument: Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) If ContentControl.Type = wdContentControlCheckBox Then If ContentControl.Range.Information(wdWithInTable) Then If ContentControl.Checked Then ContentControl.Range.Cells(1).Shading.BackgroundPatternColor = wdColorYellow Else ContentControl.Range.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic End If End If End If End Sub
Save the document, enable macros only if the file is trusted, then check a table checkbox and click elsewhere to leave the control. Uncheck it and leave the control again to restore automatic shading.

Edit Word tables with WPS Writer
WPS Writer is a free, lightweight alternative for editing documents and formatting tables. Its familiar interface and support for common Word formats make it easy to move existing documents into WPS. The Word VBA event described above is a Microsoft Word solution and is not guaranteed to run in WPS.

Frequently Asked Questions
Why doesn’t the cell color change immediately when I check the box?
The example uses Word’s ContentControlOnExit event. After changing the checkbox, click elsewhere to leave the control and trigger the shading update.
Can I use the same code with a legacy checkbox?
No. The example handles checkbox content controls. A legacy form field needs a separate macro configured for that field, while an ActiveX checkbox uses its own event handling.
What happens to the cell’s original shading when I clear the checkbox?
The example sets the cell shading to automatic when the checkbox is cleared. It does not restore a custom color that was previously applied.
Why should I save the document as a DOCM file?
A Word Macro-Enabled Document (*.docm) can store the VBA procedure. Use File > Save As to select that format, and enable macros only for trusted files.




