![]() |
|
|
|
#1
|
||||
|
||||
|
I would be using Mapped Plain Text Content Controls to do this and the user could import that data from Excel as an XML file. This can be automated with a macro to replace the xml file (or set its values) and avoid working with the text via find and replace.
Your Excel data needs to be in fieldname/value pairs. In Excel this could be a second column eg. object1...Joe object2...Smith object3...123 Main St object4...Springfield Your original question would enable you to insert all the necessary Content Controls but would need to include either setting the Title/Tag properties to the fieldname or setting the mapping. Alternatively, if you are using a find/replace method recommended by Paul, then you would need to make sure you search all stories to get entries in the headers/footers etc.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#2
|
|||
|
|||
|
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 |
|
|
|
Similar Threads
|
||||
| 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 |
Push Word content control data and excel cells
|
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 |