Would like to select all text with shading in a given document

Y

Yvonne

I have a Microsoft Word document (around 100 pages), and most of the
document is in regular text, but some parts of it are shaded gray. I
would like to make a second document containing only the gray-shaded
text. I would rather not have to tediously copy and paste each shaded
area by hand. I have tried the help menu several times for advice,
but haven't found anything that works. The closest thing I could find
was, "select all text with the same formatting," but when I tried
that, it didn't work, because not all of the shaded text has the same
formatting (some is italic, some is in a different font, etc.). The
only thing that all of the text I want has in common is that it's all
shaded. Any advice on how to copy and paste the shaded parts easily?
 
D

Doug Robbins - Word MVP

Run a macro containing the following code:

Dim Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey wdStory
Selection.Find.Highlight = True
With Selection.Find
Do While .Execute(FindText:="", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Target.Range.InsertAfter Selection.Range & vbCr
Selection.MoveRight wdCharacter, 1
Loop
End With

If you want the text in the new document shaded as well, then use:

Dim Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
Dim trange As Range
Source.Activate
Selection.HomeKey wdStory
Selection.Find.Highlight = True
With Selection.Find
Do While .Execute(FindText:="", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Set trange = Target.Range
trange.InsertAfter vbCr
trange.Collapse wdCollapseEnd
trange.FormattedText = Selection.Range.FormattedText
Selection.MoveRight wdCharacter, 1
Loop
End With
Target.Paragraphs(1).Range.Delete



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
Y

Yvonne

Thanks for your help. Unfortunately, I tried this, but it didn't
work. It only copied a few lines, and included all kinds of other
random characters.
 
D

Doug Robbins - Word MVP

Can you be more specific about what you are starting with and what was the
result?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Thanks for your help. Unfortunately, I tried this, but it didn't
work. It only copied a few lines, and included all kinds of other
random characters.
 

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