Loop doc and change color if sentence starts with 'string'

F

Filips Benoit

Dear All,

How can I change the color of all sentences that starts with a string (
inputbox).

Goal: projection of the text of a play for deaf people above the stage.
Technically it is possible.
I want a different color for each player and hope to color the sentences
with a marco.
I think I'll need 1 macro for each color.


Thanks,

Filip
 
F

Filips Benoit

Had no patience and found it myself !

Sub KleurParagraafBeginnendeMETxxxx()
'
' KleurParagraafGroen Macro
' Macro created 31-8-2007 by Filips Benoit
'
Dim para As Object
Dim strFind As String
Dim strKleur As String
Dim strSuccesMsg As String
Dim iLongstrFind As Long

strFind = InputBox("Zoekstring", "Zoek en kleur paragraaf = blauw", ,
2000, 2000)
iLongstrFind = Len(strFind)

strKleur = InputBox("Kleur?", "Kleur opgeven, aub", , 2000, 2000)
Select Case strKleur
Case "geel": strSuccesMsg = "OK"
Case "blauw": strSuccesMsg = "OK"
Case "groen": strSuccesMsg = "OK"
Case "wit": strSuccesMsg = "OK"
Case Else: strSuccesMsg = "Kleur niet geschikt voor projectie of
niet beschikbaar"
End Select


If strSuccesMsg = "OK" Then
' Move to beginning of document.
Selection.HomeKey Unit:=wdStory
For Each para In ActiveDocument.Paragraphs
Selection.StartOf Unit:=wdParagraph
Selection.MoveEnd Unit:=wdParagraph

If Left$(Selection.Text, iLongstrFind) = strFind Then
With Selection.Font
Select Case strKleur
Case "geel": .Color = wdColorYellow: strSuccesMsg =
"OK"
Case "blauw": .Color = wdColorBlue: strSuccesMsg =
"OK"
Case "groen": .Color = wdColorGreen: strSuccesMsg =
"OK"
Case "wit": .Color = wdColorWhite: strSuccesMsg =
"OK"
End Select
End With
End If
Selection.Move wdParagraph
Next para
Selection.HomeKey Unit:=wdStory

Else
MsgBox strSuccesMsg
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top