Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-22-2025, 08:34 AM
MJH001 MJH001 is offline Find the first chord in a song Windows 11 Find the first chord in a song Office 2019
Novice
Find the first chord in a song
 
Join Date: Sep 2025
Posts: 6
MJH001 is on a distinguished road
Default 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
Reply With Quote
 

Tags
color font, find character



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting song lyrics Lakshman Word 2 08-17-2021 07:17 AM
Find the first chord in a song Song in Powerpoint aclare PowerPoint 5 04-09-2017 01:48 AM
Find the first chord in a song Set song as different animation beedee PowerPoint 1 05-04-2014 10:21 AM
Find the first chord in a song Is it possible to play a song even after the slides loop? Mihai_VRD PowerPoint 1 04-17-2012 01:06 AM
Please help......[embed song in presentation] elmcity PowerPoint 0 01-09-2010 12:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft