I have the following macro which searches and replaces ALL text, I only need to replace text that has a paragraph style of “Chord”. Failing that, possibly just a character style of Bold might work. How can I search on just that style?
Sub convert
Dim I As Long
Dim Doc As Object
Dim Replace As Object
Dim SourceWords(17) As String
Dim DestWords(17) As String
Dim Enum1 As Object
Dim Enum2 As Object
Dim TextElement As Object
Dim TextPortion As Object
'On Local Error Goto Fin
Doc = ThisComponent
Enum1 = Doc.Text.createEnumeration
' loop over all paragraphs
While Enum1.hasMoreElements
TextElement = Enum1.nextElement
If TextElement.supportsService("com.sun.star.text.Paragraph") Then
Enum2 = TextElement.createEnumeration
' loop over all paragraph portions
While Enum2.hasMoreElements
TextPortion = Enum2.nextElement
SourceWords() = Array("Gb","G","G#","Ab", "A", "A#", "Bb", "B", "C", "C#", "Db", "D", "D#","Eb","E","F","F#")
DestWords() = Array("1b","1","1#","2b", "2", "2#", "3b", "3", "4", "4#", "5b", "5", "5#", "6b","6", "7", "7#")
Replace = Doc.createReplaceDescriptor
For I = 0 To 17
If TextPortion.ParaStyleName = "Chord" Then
Replace.SearchString = SourceWords(I)
Replace.ReplaceString = DestWords(I)
Doc.replaceAll(Replace)
End If
Next I
Wend
Endif
Wend
Fin:
End Sub