View Single Post
 
Old 02-14-2023, 05:56 PM
Aarish Khawar Aarish Khawar is offline Windows 10 Office 2021
Novice
 
Join Date: Feb 2023
Posts: 4
Aarish Khawar is on a distinguished road
Default Using VBA to map Rich text CC to a Dropdown list in a Combo Box

Hello All,

I should preface this with the fact that I am quite new to VBA and Macros and am still learning the basics.

I'm trying to build a form within a table that contains a drop-down list (Combo Box - as I want the user to have the option of entering their own value if none of the options meet their requirements) of options that I want the user to be able to select from. Once the user has selected an option, I want a custom paragraph to appear within a rich text content control (RTCC) box which is located later in the document.

From what I understand, the best way to do this is to have each custom paragraph in a separate RTCC with its own "title". So that once mapped to the drop-down list, the specific RTCC is the only one visible when an option from the drop-down list is selected. I would prefer that none of the RTCCs are visible if no option has yet been selected purely for aesthetic reasons but I am willing to let this slide. Also, it would be ideal if the custom paragraphs updated "OnChange", however "OnExit" is good too.

So far, I've been able to add titles to each RTCC and the following code down:

Sub ShowParagraph()
Dim sParagraph As String
sParagraph = ActiveDocument.ContentControls("Combo Box").Range.Text
Select Case sParagraph
Case "BCA_DCC"
ActiveDocument.ContentControls("BCA_DCC.TXT").Rang e.Text = "This is paragraph 1"
Case "BCA_NODCC"
ActiveDocument.ContentControls("BCA_NODCC.TXT").Ra nge.Text = "This is paragraph 2"
Case "SOA_DCC"
ActiveDocument.ContentControls("SOA_DCC.TXT").Rang e.Text = "This is paragraph 3"
Case "SOA_NODCC"
ActiveDocument.ContentControls("SOA_NODCC.TXT").Ra nge.Text = "This is paragraph 4"
End Select
End Sub

Where values e.g., "BCA_DCC" are options in the drop-down list and "BCA_DCC.TXT" are titles for their corresponding RTCC containing custom paragraphs.

Note: I am using the latest version of Word.

Any feedback would be highly appreciated!

Best,
Aarish
Reply With Quote