Finding All Words with Specific Format -- via Macro

D

Dogwoodnc

I'm trying to create a macro that will:
a) Find all words/terms in a doc that are formatted blue
b) Copy those words/terms and paste them into a (new) blank document

I've been able to do this manually (via Find/ Highlight All Occurrences/
Format(Font)/ Find All/ Copy/ New Doc/ Paste). However, I have not been able
to get a macro to contain these commands.

Any suggestions??

THANKS in advance!
 
G

Graham Mayor

How about

Sub CopyBlueToOtherDoc()
Dim Source As Document
Dim Target As Document
Dim oRng As Range
Dim sView As String
Set Source = ActiveDocument
sView = ActiveWindow.View.ShowFieldCodes
Set Target = Documents.Add
Application.ScreenUpdating = False
Source.Activate
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Font.Color = wdColorBlue
Do While .Execute(findText:="", _
MatchWildcards:=False, Wrap:=wdFindStop, _
Forward:=True) = True
Set oRng = Selection.Range
Target.Range.InsertAfter oRng & vbCr
Loop
End With
End With
Target.Activate
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Dogwoodnc

This macro worked BEAUTIFULLY for us in Word 2003. However, we're now
preparing to migrate to 2007, and when I try to run it there, it does not
locate any file names (even though there ARE folders in the files). Are
there any tweaks needed for use with 2007?

Thanks in advance!
 
G

Graham Mayor

The macro in the post you referred to does not have anything to do with
files nor folders. It simply searches the current document for blue coloured
text and writes any such text found to a new document. That should work just
as readily in Word 2007 as it does in Word 2003. Can you clarify what yoiu
are trying to do?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Dogwoodnc

So sorry, I'm trying to troubleshoot a lot of different macros and was
thinking about another one when I wrote.

I just tried re-copying the original code and it worked perfectly. I'm not
sure why it was acting up previously.

Thanks for your patience; this one seems to be solved now!
 

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