Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-19-2012, 01:20 PM
gmaxey gmaxey is offline Creating a plain text content control for every instance of a word or phrase Windows 7 32bit Creating a plain text content control for every instance of a word or phrase Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

HTML Code:
Sub AddContentControlAndMapToLocalXML()
Dim oCC As Word.ContentControl
Dim oCustomPart As Office.CustomXMLPart
Dim xmlPart As String
Dim doc As Word.Document
Set doc = ActiveDocument
Dim oRng As Word.Range
Dim strToFind As String
ClearXMLParts
xmlPart = "<?xml version='1.0' encoding='utf-8'?><Root><Item></Item></Root>"
Set oCustomPart = doc.CustomXMLParts.Add(xmlPart)
strToFind = "Text to find"
Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = strToFind
    .Wrap = wdFindStop
    While .Execute
      Set oCC = doc.ContentControls.Add(wdContentControlText, oRng)
      oCC.XMLMapping.SetMapping "/Root/Item[1]", , oCustomPart
      oCC.Range.Text = strToFind
      oRng.Collapse wdCollapseEnd
      Do While oRng.InRange(oCC.Range)
        oRng.Move wdCharacter, 1
      Loop
    Wend
  End With
End Sub
'Run ClearXMLParts prior to testing these examples.
Sub ClearXMLParts()
Dim i As Long
'MsgBox ActiveDocument.CustomXMLParts.Count
For i = ActiveDocument.CustomXMLParts.Count To 4 Step -1
  ActiveDocument.CustomXMLParts(i).Delete
Next i
End Sub
 
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

Tags
content control, find & replace, xml



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a plain text content control for every instance of a word or phrase Rich text/Plain text Content Controls in Template michael.fisher5 Word 9 11-19-2014 06:36 AM
Creating a plain text content control for every instance of a word or phrase How do you set rich text in a content control Testor Word VBA 4 07-08-2012 07:55 AM
Word2010 check boxes and plain text content control boxes in same table fcsungard Word 5 06-01-2012 01:16 AM
Creating a plain text content control for every instance of a word or phrase Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft