Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 12-12-2012, 02:05 PM
gmaxey gmaxey is offline Replace text with Quick Part using VBA Windows 7 32bit Replace text with Quick Part using VBA Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
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
 

Tags
content control, vba in microsoft word, word 2007



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace text with Quick Part using VBA Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
How to Rename a Quick Part sleake Word 14 10-14-2013 09:21 AM
quick replace, sort, change columns userman Excel 1 05-01-2012 06:24 AM
Quick change for all text boxes in a presentation tmlander PowerPoint 1 03-09-2012 01:20 AM
Date display in Mod quick part header Jrul John Word 1 08-02-2010 12:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:00 PM.


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