PDA

View Full Version : Change highlighted text to bulleted lists



andysjp
03-14-2017, 08:07 AM
Hi there,

I need a Word macro that scans an entire document and makes any text which is highlighted as wdYellow into a bulleted list, and any text highlighted as wdTeal into sub-bullets.

All highlighting then needs to be removed.

Can anybody please help?

Thanks
Andy

Programmer_n
03-14-2017, 06:04 PM
Are the highlighted texts a single word or phrase or sentence?

What is your effort so far?

Do check out this link for converting sentences to bullet points. You could add a highlight search for it. Although it is a problem due to sentence boundary detection problem.

http://www.vbaexpress.com/forum/archive/index.php/t-56949.html

andysjp
03-15-2017, 02:00 AM
They are sentences. They start out as bulleted lists but then my macro does a load of other formatting including using the "No spacing" style, which removes the bullets. So I got it to highlight all the bullets before it gets to the bit where it does the No Spacing, so that at the end of the macro it can find highlights and put the bullets back in. I've tried several things but nothing that I wouldn't be too embarrassed to post on here!!

gmaxey
03-15-2017, 06:01 AM
Why don't you post your macro?

Programmer_n
03-15-2017, 06:53 AM
They are sentences. They start out as bulleted lists but then my macro does a load of other formatting including using the "No spacing" style, which removes the bullets. So I got it to highlight all the bullets before it gets to the bit where it does the No Spacing, so that at the end of the macro it can find highlights and put the bullets back in. I've tried several things but nothing that I wouldn't be too embarrassed to post on here!!

Input:

On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.

You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can also format text directly by using the other controls on the Home tab. Most controls offer a choice of using the look from the current theme or using a format that you specify directly.

Output:

On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks.

When you create pictures, charts, or diagrams, they also coordinate with your current document look.




You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can also format text directly by using the other controls on the Home tab.

Most controls offer a choice of using the look from the current theme or using a format that you specify directly.

Is this what are you looking, assuming yellow colored words are highlighted as wdyellow.

Programmer_n
03-15-2017, 07:16 AM
Sub highlight_bullet()
Dim char As Range
For Each char In ActiveDocument.StoryRanges
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
If char.HighlightColorIndex = wdYellow Then
With Selection.Find
.Text = ". "
.Replacement.Text = ".^p"
End With
End If
Next
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Range.ListFormat.ApplyBulletDefault
End Sub


This code doesnot solve your problem but I presume it takes you in the right direction. When you do select all and run this code, This code changes every detected sentences ending in .Space to a bullet point, It is supposed to detect yellow highlight, unsure why it does not. Sorry for abrupt answer, some one else will refrain it,I am adding this to my weekend task.

gmaxey
03-15-2017, 07:40 AM
Sub highlight_bullet()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Highlight = True
While .Execute
If oRng.HighlightColorIndex = wdYellow Then
oRng.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
oRng.HighlightColorIndex = wdAuto
End If
If oRng.HighlightColorIndex = wdBrightGreen Then
oRng.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
oRng.SetListLevel Level:=2
oRng.HighlightColorIndex = wdAuto
End If
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub

andysjp
03-17-2017, 03:27 AM
Thank you for this

andysjp
03-17-2017, 03:28 AM
This works beautifully - thank you immensely