sand60
04-19-2016, 07:11 AM
Hello to all,
Greetings!
I am learning how to use vba. So am very new.
I found this thread that highlights word.
Find and highlight first occurrence each word from list separate table
I am trying to adapt it to my situation, not sure if its the best approach but here goes.
What I am trying to do - search through my document and format the lists only.
Each list has a different first word color that needs to be applied.
Example
If the previous paragraph word is Blue : make all the first words in the list underneath blue
Blue
Apples - fruit
oranges - tasty
pears - delicious
Green
Island - nice
USA - party
Europe - place
If the previous paragraph word is green make all the first words in that list green and so on.
I couldn't think of a place holder so i though if the previous word is something do something.
Sub ListFirstWordsFormat()
Dim PreviousPara As Paragraph
Dim para As Paragraph
Dim list_item As Boolean
list_item = False
For Each para In ActiveDocument.Paragraphs
If para.Range.ListFormat.ListType = WdListType.wdListBullet Then
para.Range.Words(1).Font.Bold = True
Do While .Execute
'Select Case
Case 1: If PreviousPara = Black Then para.Range.Words(1).Font.Bold = True
Case 2: If PreviousPara = Blue Then para.Range.Words(1).Font.Bold.color = wdblue
Case 3: If PreviousPara = Green Then para.Range.Words(1).Font.Bold.color = wdgreen
End Select
oRng.Collapse wdCollapseEnd
If lngFound = lngCol Then Exit Do
Loop
End With
End If
Next
End Sub
I have a brief skeleton out line, but nothin cohesive,
I don't mind using a table to store the words if thats an option, or using more case statements.
Thank you very much for your consideration and advice
sand
Greetings!
I am learning how to use vba. So am very new.
I found this thread that highlights word.
Find and highlight first occurrence each word from list separate table
I am trying to adapt it to my situation, not sure if its the best approach but here goes.
What I am trying to do - search through my document and format the lists only.
Each list has a different first word color that needs to be applied.
Example
If the previous paragraph word is Blue : make all the first words in the list underneath blue
Blue
Apples - fruit
oranges - tasty
pears - delicious
Green
Island - nice
USA - party
Europe - place
If the previous paragraph word is green make all the first words in that list green and so on.
I couldn't think of a place holder so i though if the previous word is something do something.
Sub ListFirstWordsFormat()
Dim PreviousPara As Paragraph
Dim para As Paragraph
Dim list_item As Boolean
list_item = False
For Each para In ActiveDocument.Paragraphs
If para.Range.ListFormat.ListType = WdListType.wdListBullet Then
para.Range.Words(1).Font.Bold = True
Do While .Execute
'Select Case
Case 1: If PreviousPara = Black Then para.Range.Words(1).Font.Bold = True
Case 2: If PreviousPara = Blue Then para.Range.Words(1).Font.Bold.color = wdblue
Case 3: If PreviousPara = Green Then para.Range.Words(1).Font.Bold.color = wdgreen
End Select
oRng.Collapse wdCollapseEnd
If lngFound = lngCol Then Exit Do
Loop
End With
End If
Next
End Sub
I have a brief skeleton out line, but nothin cohesive,
I don't mind using a table to store the words if thats an option, or using more case statements.
Thank you very much for your consideration and advice
sand