View Single Post
 
Old 12-12-2012, 02:05 PM
gmaxey gmaxey is offline Windows 7 32bit 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

It continues to run here. The error sounds like the range spans an existing CC. Start with a fresh version of the document and see if it won't work:

PHP Code:
Sub ReplaceWithConentControlBoundToABuiltInDocProperty()
Dim oRng As Word.Range
Dim strFind
() As String
Dim strInput 
As String
Dim i 
As Long
Dim oCC 
As ContentControl
strFind
() = Split("This student|STUDENT|your name""|")
strInput InputBox("Enter the replacement name:""Input")
For 
0 To UBound(strFind)
  
Set oRng ActiveDocument.Range
  With oRng
.Find
    
.ClearFormatting
    
.Replacement.ClearFormatting
    
.Text strFind(i)
    .
Forward True
    
.Wrap wdFindContinue
    
.Format False
    
.MatchCase False
    
.MatchWholeWord True
    
.MatchWildcards False
    
.MatchSoundsLike False
    
.MatchAllWordForms False
    
While .Execute
      Set oCC 
ActiveDocument.ContentControls.Add(wdContentControlTextoRng)
      
With oCC
        
'High jack the "Comments" document property.
        .XMLMapping.SetMapping "ns1:coreProperties[1]/ns0:description[1]", , ActiveDocument.CustomXMLParts(1)
        .Range.Text = strInput
        .Title = "Name"
      End With
    Wend
  End With
Next
End Sub 
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote