Hello!
I am new here so I apologize in advance if I break any rules. I work with technical fields and choices are often indicated with square brackets e.g. [option 1][option 2]. I am trying to write a macro to turn a selection of square backets into a dropdown content control. Is this something that is feasible?
Below is my attempt. I am not a programmer, so it might not make sense. It is patchwork from different snippets I have found over various forums. I have also attached a picture to illustrate what I am trying to do.
Thanks so much!
Code:
Sub Macro ()
Application.ScreenUpdating = False
Dim objCC As ContentControl
Dim Strtext As String
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\[*\]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While Selection.Find.Found
StrTxt = Selection.Find.Text
Set objCC = Selection.ContentControls _
.Add(wdContentControlComboBox)
objCC.Title = "Selection"
objCC.SetPlaceholderText _
Text:="Please make a selection"
For Each Strttext In Selection.Find.Text
objCC.DropdownListEntries.Add StrTxt
Loop
End With
Application.ScreenUpdating = True
End Sub