Thanks Paul and Andrew.
I think the mapping you mentioned would be ideal once we have the words tagged as plain text content control objects.
So the Title would be the Object name, and the Tag would be DocumentVariable always.
Circling back to my original questions is it possible to scan the document for the words from an excel list? Let's say I have 10 documents with all the same possible variables that would to be converted to Content Control Objects.
I found a post on how someone built a find and replace based of an excel list:
Sub Main()
Dim xl as Object 'Excel.Application
Dim wb as Object 'Excel.Workbook
Dim ws as Object 'Excel.Worksheet
Dim rng as Object 'Excel.Range
Dim cl as Object 'Excel.Range
Set xl = CreateObject("Excel.Application")
Set wb = xl.Workbooks.Open("c:\folder\file.xlsx") '## Modify as needed
Set ws = wb.Sheets(1) '##Modify as needed
Set rng = ws.Range("A1", ws.Range("A1").End(xlDown))
For each cl in rng
Call Macro5(cl.Value, cl.offset(0,1).Value)
Next
End Sub
Sub Macro5(findText$, replaceText$)
'
' Macro5 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = findText
.Replacement.Text = replaceText
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute
End Sub
Original post here:
vba - "Find and Replace" multiple words in Word from Excel list - Stack Overflow
Would it be possible to change that to apply the content control instead of the word replacement?
Maybe something like this? if Macro5 above was changed out.
Sub ReplaceTags(findText)
With Selection.Find
.ClearFormatting
.Text = findText
.Forward:=True
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Range.ContentControls.Add (wdContentControlText)
Selection.ParentContentControl.Title = Selection.Text
Selection.ParentContentControl.Title = "DocumentVariable"
End Sub