Search and change automatically

  • Thread starter Thread starter Gene
  • Start date Start date
G

Gene

Could I use Word to change this:
[g] Where have all the [em} flowers gone, [c] long time [d] passing.
to having everything in and including the [ ] brackets change to bold and
capitals so it would be like this:
[G] Where have all the [Em} flowers gone, [C] long time [D] passing. ((but
in bold, I can't seem to format that here)).
I think I need to create some type of lookup table as [em] might come out
[EM] and something like [d#m7] need to be [D#m7].
Right now I type everything and use a manual search and replace to do this
and sometimes miss one [X] when it is a chord that changes only once and I
miss searching for it.
Thanks in advance for any comments/suggestions.
Gene
 
Assuming that [em} was an error that was meant to be [em],

The following macro will do what you want:

Dim myrange As Range
Dim i As Long
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\[[a-z]{1}", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set myrange = Selection.Range
myrange.End = ActiveDocument.Range.End
i = InStr(myrange, "]")
myrange.End = myrange.Start + i
myrange.Text = "[" & UCase(myrange.Characters(2)) & Right(myrange,
Len(myrange) - 2)
myrange.Font.Bold = True
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
Yes that was a typo error.
This macro works Fantastic. Thank you ever so much for taking the time to
assist me. It is greatly appreciated and will save me from a lot of
headaches when I type out my music. I'll have to study this to see how it
was constructed. Might take a while as I know nothing about this
'language'. I do see that Word has a help section for this though. At
first I thought of using autocorrect but that would have required adding
entries for every combination I might use within those brackets. Again,
your time, help and expertise is appreciated......... Gene

Doug Robbins - Word MVP said:
Assuming that [em} was an error that was meant to be [em],

The following macro will do what you want:

Dim myrange As Range
Dim i As Long
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\[[a-z]{1}", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set myrange = Selection.Range
myrange.End = ActiveDocument.Range.End
i = InStr(myrange, "]")
myrange.End = myrange.Start + i
myrange.Text = "[" & UCase(myrange.Characters(2)) & Right(myrange,
Len(myrange) - 2)
myrange.Font.Bold = True
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Gene said:
Could I use Word to change this:
[g] Where have all the [em} flowers gone, [c] long time [d] passing.
to having everything in and including the [ ] brackets change to bold and
capitals so it would be like this:
[G] Where have all the [Em} flowers gone, [C] long time [D] passing.
((but in bold, I can't seem to format that here)).
I think I need to create some type of lookup table as [em] might come out
[EM] and something like [d#m7] need to be [D#m7].
Right now I type everything and use a manual search and replace to do
this and sometimes miss one [X] when it is a chord that changes only once
and I miss searching for it.
Thanks in advance for any comments/suggestions.
Gene
 
Back
Top