Forum Discussion
Automatically update text depending on contents of a content control in Word
ChrisUoN Firstly, to control what appears in the Content Control, I would recommend that you use a Combo Box Content Control that contains the Phase 1, Phase 2 and Phase 3 as the only items that can be selected. Then set the Title of the Content Control to "Phase", then paste the following code into the ThisDocument Object in the Visual Basic Editor:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
If ContentControl.Title = "Phase" Then
Select Case ContentControl.Range.Text
Case "Phase 1"
ThisDocument.Variables("varPhase").Value = "One"
Case "Phase 2"
ThisDocument.Variables("varPhase").Value = "Two"
Case "Phase 3"
ThisDocument.Variables("varPhase").Value = "Three"
Case Else
ThisDocument.Variables("varPhase").Value = "Nothing Selected"
End Select
End If
ThisDocument.Range.Fields.Update
End Sub
- DpaulheskAug 30, 2024Copper ContributorHow does one show the results of this in the Word document? I can't tell from here how to show the output. Thanks.
- Charles_KenyonAug 31, 2024Bronze Contributor
The results of a choice in a ComboBox or Drop-Down Content Control in Word are shown in the control in the document.
To have the results show up elsewhere you need a mapped control or another method.
- DpaulheskAug 31, 2024Copper ContributorI'm sorry. I wasn't clear. The OP said, "I want a piece of text elsewhere in the document to automatically update with some corresponding text." If I use the VBE that you wrote out, above. How can I get the Value ("One", "Two", etc.) to appear elsewhere in the document?
- ChrisUoNJun 30, 2023Copper Contributor
Doug_Robbins_Word_MVP
Thanks a lot, Doug! That works great.Is there any way something like this can work in Word online? I assume Visual Basic can't be used online.
- Charles_KenyonJun 30, 2023Bronze Contributor
Differences between using a document in the browser and in Word
See Compare Word features on different platforms - Office Support.
- These programs are all named Word and they are all created and published by Microsoft.
- They all can edit the same document files that have the same file structure. Some of the programs have no control over some of the document structures.
- But, they are different programs with different features and controls.
As of March, 2023, the most powerful one of these, with the most features, is the Windows desktop application. I do not expect that to change.
The Macintosh desktop application is second with number of features. The things available in the Windows version not yet on the Mac version include Content Controls, Building Blocks, UserForms, and ActiveX. It can use, but cannot create, or modify most Content Controls. AutoText is a Building Block that the Mac can and does use.
The browser version of Word – Word Online – has a Transcribe feature that is not available in any of the other Word programs. Otherwise, the browser version has far fewer features and editing in it has been reported to mess up automatic numbering. Chromebooks use a version of this or of the Android mobile app.
The mobile applications vary somewhat but have far fewer features. I would use them for note taking and for quick viewing/printing, but not for editing. Especially not for editing long or complex documents.
- Jun 30, 2023
ChrisUoN Hi Chris,
Compared to the Desktop application, the On-Line Word application is not good for anything much other than reading documents