Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-03-2017, 10:52 PM
sylvio sylvio is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Jan 2017
Posts: 12
sylvio is on a distinguished road
Default find with wild cards and add into CC

Good day

I cannot understand what is the problem with the code below.
I am trying to put every line of the text in separate content controls:

<paragraph mark> just some text <paragraph mark>


<paragraph mark> another piece of some text <paragraph mark>
<paragraph mark> just some text <paragraph mark>

With wild card "[!^13]@some*^13" the code looks for complete string embraced by paragraph marks and puts it into CC, but somehow the code falls into endless loop. With Ctrl+Break I can see that the job is done, so in general the code is ok.
What is the point?

Code:
Sub Add_CC_w_Title()

Dim oCC As Word.ContentControl
Dim doc As Word.Document
Dim oRng As Range
Set doc = ActiveDocument
Set oRng = ActiveDocument.Range
    
    With oRng.Find
            .Text = "[!^13]@some*^13"
            .Wrap = wdFindContinue
            .MatchWildcards = True
            
            While .Execute
                'oRng.Font.Color = wdColorRed
                Set oCC = doc.ContentControls.Add(wdContentControlText, oRng)
                oCC.Title = "title"
            Wend
    End With

End Sub
Reply With Quote
  #2  
Old 09-03-2017, 11:37 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,352
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Try:
Code:
Sub Add_CC_w_Title()
Dim oCC As Word.ContentControl
With ActiveDocument.Range
  With .Find
    .Text = "[!^13]@some*^13"
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    Set oCC = .ContentControls.Add(wdContentControlText, .Duplicate)
    oCC.Title = "title"
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
End Sub
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 09-04-2017, 01:00 AM
sylvio sylvio is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Jan 2017
Posts: 12
sylvio is on a distinguished road
Default

Just perfect! Thank you.
Reply With Quote
Reply

Tags
content control
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove repeated words with " macro " or " wild cards " in texts with parentheses and commas jocke321 Word VBA 2 12-10-2014 11:27 AM
Question about find and replace wild cards catherineliang Word 1 07-21-2014 09:42 PM
Wild card to highlight capitalised terms? bertietheblue Word 2 02-08-2013 04:44 PM
Printing on 3x5 cards Jennifer Murphy Word 0 08-05-2011 06:00 PM
Bingo Cards office_mike Excel 1 11-29-2008 10:17 PM


All times are GMT -7. The time now is 03:00 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft