Find the first chord in a song
I'm writing a macro which extracts songs from a master songbook and puts them a new document. I've got it all working (thanks to macropod), but I need an enhancement.
I want to find the first instance of "[x]" in red (where [x] is the musical key of the song eg [Am], [C] etc) within the range of the song I have just set.
I want to copy this (including the brackets) into a variable (SongKey) for later pasting into a table also with the song title.
Here is the section of code which extracts the song and it's title. I've marked the sport where I need to copy the [x], but I have no idea how to select text by colour.
Also the string may be 3 OR 4 characters long, including brackets, but always ends with a "]".
Any help appreciated. Apologies I do not yet know how to make pasted code look neat.
' GET WHOLE SONG (always only one page)
Windows(LatestSongbook).Activate
Set rng = ActiveDocument.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=NextPage) ' marks START of page range
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=NextPage ' marks END of page range (ie 1 page only)
rng.End = Selection.Bookmarks("\Page").Range.End ' marks physical end of page
rng.Copy
' HERE: need to find first instance of "[x]" in red (where [x] is the musical key of the song, eg [C], [Am] etc)
' need to copy this text, including start and end bracket into a variable SongKey for later insertion into the set list table
Set rng = rng.Paragraphs(1).Range ' gets song title (para 1) for later insertion into set list table
SongTitle = rng.Text
SongTitle = Left(SongTitle, Len(SongTitle) - 1) ' trim style separator off end of title
PS: the Red is RGB(255,0,0)
Last edited by MJH001; 09-22-2025 at 08:46 AM.
Reason: Added a PS to clarify colour
|