Need a macro to search for specific font type

S

steve.reed

I am trying to write a macro that will search through a document for
text with a specific font attribute (Comic SANS MS) then copy that text
to the clipboard. After copying the text, the insertion point moves to
a summary table at the beginning of the doc, where the clipboard is
pasted into a table. Then I search for the next occurance of the text
with the Comic SANS MS font attribute.

I can do all the other stuff, but I just can't get VBA to search and
find a font attribute.

I have tried using the Find and Replace dialog, and in normal use, I
can find the text, but recording those actions and then using it within
amacro, it will not find the text with the Comic SANS MS attribute.

I have Word 2002. Any suggestions?
 
G

Greg Maxey

Steve,

Try this:

Sub Test()
Dim myRng As Range
Set myRng = ActiveDocument.Range
With myRng.Find
.Text = ""
.Format = True
.Font.Name = "Comic Sans MS"
While .Execute
MsgBox "Here is a bit of that text: " & myRng
Wend
End With

End Sub
 
R

Robert

Hello Greg,
I would like to use your code for a similar task but unlike Steve I'm
not sure how to proceed further.
I want to copy into Column 1 of an existing Table all the (single)
words in a short text that have been given the Background Pattern Color
of wdBlue. Finding them, thanks to your code, will be easy. The rest
will not be for this Newbie.

Table(1) will already be partially complete with other data when this
macro begins. So we need to find the first available cell in Column 1.
Then, how do we copy each single word into the Table - preferably
along with its blue background formatting if possible.
Finally, it may happen that the Table doesn't have enough rows, so the
code will need to add more at the bottom as it goes along, if
necessary. (Or will this happen automatically within VBA?)
Is all this feasible, do you think? Could you help with the coding if
it's not too onerous a task?

Thank you in advance.
Robert
 

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