Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2012, 02:55 PM
RobsterCraw RobsterCraw 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 32bit
Novice
Creating a plain text content control for every instance of a word or phrase
 
Join Date: Nov 2012
Posts: 11
RobsterCraw is on a distinguished road
Default

Thanks gmaxey


I took your code and tried to modify it to find the title of a CC whose content matches the search text first and then use that title instead of master, but I am getting an error on the line marked with an *.

HTML Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Dim oCC As ContentControl
Dim i As Long
Dim oCCTitle As String
Set oRng = ActiveDocument.Range
  With oRng.Find
    'Finds the title of the existing CC with matching text
    .Text = "Text to find"
    While .Execute
        For i = 1 To ActiveDocument.ContentControls.Count
            If ActiveDocument.ContentControls(i).Range.Text = "Text to find" Then
            'object required error on following line
*            Set oCCTitle = ActiveDocument.ContentControls(i).Title
            End If
        Next i
  End With
  With oRng.Find
    'Assumes that you already have a mapped CC in the document titled "Master"
    .Text = "Text to find"
    While .Execute
      If Not oRng.InRange(ActiveDocument.SelectContentControlsByTitle(oCCTitle).Item(1).Range) Then
      Set oCC = ActiveDocument.ContentControls.Add(wdContentControlText, oRng)
      oCC.XMLMapping.SetMapping (ActiveDocument.SelectContentControlsByTitle(oCCTitle).Item(1).XMLMapping.xPath)
      oRng.Collapse wdCollapseEnd
      End If
    Wend
  End With
End Sub
Your updated code seems to produce an error
Reply With Quote
Reply

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 02:48 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