replace text

T

Terry Holland

Hi

Im a vb programmer but unfamiliar with programming word. Im trying to write
a function that changes the forecolour and capitalises of any text between
square brackets.

eg [c]There is a house [Am] in New Orleans [E] would change so that [c],
[Am] and [E] would be coloured blue and the [c] would also change to [C]

I'd appreciate help on this

Thanks

Terry Holland
 
J

Jay Freedman

Hi Terry,

This should do:

Sub CapAndColourChords()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Text = "\[([! ]@)\]"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
Do While .Execute
oRg.MoveStart wdCharacter, 1
oRg.MoveEnd wdCharacter, -1
oRg.Font.Color = wdColorBlue
oRg.Characters.First = UCase(oRg.Characters.First)
' prepare for next search
oRg.Collapse wdCollapseEnd
Loop
End With
End Sub

For installing the macro, see
http://www.gmayor.com/installing_macro.htm. For understanding how
wildcard searches work, see
http://www.gmayor.com/replace_using_wildcards.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
T

Terry Holland

excellent. thanks very much


Jay Freedman said:
Hi Terry,

This should do:

Sub CapAndColourChords()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Text = "\[([! ]@)\]"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
Do While .Execute
oRg.MoveStart wdCharacter, 1
oRg.MoveEnd wdCharacter, -1
oRg.Font.Color = wdColorBlue
oRg.Characters.First = UCase(oRg.Characters.First)
' prepare for next search
oRg.Collapse wdCollapseEnd
Loop
End With
End Sub

For installing the macro, see
http://www.gmayor.com/installing_macro.htm. For understanding how
wildcard searches work, see
http://www.gmayor.com/replace_using_wildcards.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Hi

Im a vb programmer but unfamiliar with programming word. Im trying to write
a function that changes the forecolour and capitalises of any text between
square brackets.

eg [c]There is a house [Am] in New Orleans [E] would change so that [c],
[Am] and [E] would be coloured blue and the [c] would also change to [C]

I'd appreciate help on this

Thanks

Terry Holland
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top