View Single Post
 
Old 12-11-2012, 02:16 PM
gmaxey gmaxey is online now Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

dmarie,

I'm over my head all the time, but isn't it more fun in the deep end?

Document Properties (e.g., title, subject, comments, etc.) are stored in one of three built-in customXMLParts in a document. So, if you want you can find text and replace it with a content control and then bind that CC to the customXMLpart data node:

PHP Code:
Option Explicit
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("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 False
    
.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

Sub ScratchMacro()
'
This tells you some of the other node names and XPath
Dim oCXNOde 
As CustomXMLNode
Dim oCXNodes 
As CustomXMLNodes
Set oCXNodes 
ActiveDocument.CustomXMLParts(1).SelectNodes("//*")
For 
Each oCXNOde In oCXNodes
  Debug
.Print oCXNOde.BaseName " " oCXNOde.XPath
Next
End Sub 
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote