Add content control to all words from an Excel list in a Word document
Hello pretty new to VBA, been searching for a method to scan through an excel list and apply Content Controls to any words in that list. I found a similar thread on this site but it looks like it goes Word to Excel so I just need to try and build it the other way.
I currently have put together a macro from some I've found online which scans a document if it is in single or double brackets depending how I change the regex statement.
Anyway wondering it would be possible to scan an excel list of 64 items and then scan the word document for those items and apply content controls if they exist.
Current macro I have:
Single Bracket content control
Sub ReplaceTags()
'
' ReplaceTags Macro
'
'
Dim myRange
Set myRange = Application.ActiveDocument.Content
Dim myFind
Set myFind = myRange.Find
With Selection.Find
.ClearFormatting
.Text = "(\[)(*)(\])"
.Execute Forward:=True
.MatchWildcards = True
End With
If Selection.Find.Found = True Then
Selection.Range.ContentControls.Add (wdContentControlText)
Selection.ParentContentControl.Tag = Selection.Text
End If
End Sub
Sub ReplaceAllTags()
'
' ReplaceAllTags Macro
'
'
For i = 0 To ActiveDocument.Words.Count
Selection.EscapeKey
Application.Run MacroName:="ReplaceTags"
Next
End Sub
Now if anyone can point me to how to point this to an excel list and scan than then pass it through to the above functions that would be much appreciated.
|