![]() |
#6
|
|||
|
|||
![]()
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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Import list from Excel into drop-down content control in word | shanshan89 | Word VBA | 10 | 08-11-2022 11:53 PM |
Populate Word content control fields with data from Excel | Kapluke | Word VBA | 8 | 01-10-2022 05:39 AM |
![]() |
shaztastic | Word VBA | 13 | 08-27-2018 06:46 AM |
Combo Box Content Control: How to update the list throughout the whole document? | deepak_fer | Word | 9 | 03-18-2018 04:10 AM |
Word 2010 Content Control help - Combo Boxes vs Drop Down List | proghy | Word | 1 | 09-16-2014 02:01 PM |