VBA & Macro Problems

Change Word Table Cell Color When a Checkbox Is Selected

John WilsonJohn Wilson Nov 25, 2026 869 views

Question details

Change the background color of a Word table cell according to its checkbox state.

Change Word Table Cell Color When a Checkbox Is Selected
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.
Before you start

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.

Solution 1Recommended

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.

1
Save a macro-enabled copy

In Word, select File > Save As and choose Word Macro-Enabled Document (*.docm).

2
Open the document’s VBA code

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.

3
Add the event procedure

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

4
Test a checkbox

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.

Use a VBA event to shade cells with checkbox content controls
Other checkbox types: This event does not handle legacy form fields or ActiveX controls. Those require a different macro and event setup. For documents used on both Windows and Mac, consider legacy fields or content controls rather than ActiveX.
Free Microsoft Office alternative

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.

Edit and manually shade table cells in WPS WriterOpen and save documents in Microsoft Word formats such as DOCXUse a familiar interface for everyday document editingWork with a lightweight office suite with free core features
microsoft office alternative - wps office

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.