Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

replace text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Terry Holland - 12 Nov 2006 20:20 GMT
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
Jay Freedman - 12 Nov 2006 21:54 GMT
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>Hi
>
[quoted text clipped - 10 lines]
>
>Terry Holland
Terry Holland - 13 Nov 2006 11:09 GMT
excellent. thanks very much

> Hi Terry,
>
[quoted text clipped - 47 lines]
> >
> >Terry Holland
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.