![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I have a text with several paragraphs.
For each of them I trying to find the following combinations, and put before them a particular character: [space][one italic character] should become: §[found text] [one italic character][space][one non italic character] should become: @[found text] for example "Aaaaa bbbb cccc" should become "Aaaa§ bbbb@ cccc" Any idea? thanks in advance |
|
#2
|
||||
|
||||
|
You could use a macro like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Italic = True
.Execute
End With
Do While .Find.Found
i = i + 1
If .Characters.First = " " Then
.Characters.First.Font.Italic = False
.Start = .Start + 1
End If
.Characters.First.Previous.InsertBefore "§"
If .Characters.Last = " " Then
.Characters.Last.Font.Italic = False
.End = .End - 1
End If
.Characters.Last.InsertAfter "@"
.Characters.Last.Font.Italic = False
.End = .End + 1
.Collapse wdCollapseEnd
'The next line is only needed if the Find is based on formatting without regard to text
If (ActiveDocument.Range.End - .End) < 2 Then Exit Do
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
MsgBox i & " instances found."
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Retain source format even on combination of multiple documents of different formats
|
G.Anusha | Word | 12 | 12-14-2021 03:31 PM |
| Is it possible to have a style apply two formats based upon text? | DMcCollum | Word | 3 | 05-02-2015 06:29 PM |
Way to search for a string in text file, pull out everything until another string?
|
omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |
One line of text - two formats?
|
judicial85 | Word | 4 | 02-18-2011 04:24 AM |
| Forms: combination of a list and a text field to be filled in | bart014 | Word | 0 | 04-23-2010 12:55 AM |