Specifying find format with VBA

P

Philip Brown

Hello,

Trying to use VBA to Find a given font and replace it
with another font, but cannot figure out how to specify
this.

Current code reads:
With Selection.Find
.Text = "^?"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

Thanks for any help!

Philip Brown
 
M

Mark Tangard

Philip,

You don't want anything to be in the .Text slots. Just use
the .Font property to specify the before & after fonts::

With Selection.Find
.Text = ""
.Replacement.Text = ""
.Font.Name = "Times New Roman"
.Replacement.Font.Name = "Tahoma"
.Wrap = wdFindContinue
.Forward = True
.Format = True
.MatchCase = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
 
P

Philip Brown

Thank you much!
-----Original Message-----
Philip,

You don't want anything to be in the .Text slots. Just use
the .Font property to specify the before & after fonts::

With Selection.Find
.Text = ""
.Replacement.Text = ""
.Font.Name = "Times New Roman"
.Replacement.Font.Name = "Tahoma"
.Wrap = wdFindContinue
.Forward = True
.Format = True
.MatchCase = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With

--
Mark Tangard, Microsoft Word MVP
Please reply only to the newsgroup, not by private email.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters


.
 
K

Kdarlaomer

Mark,

1. What if I want to change font only for digits (and not
for letters)?

2. I've tried the same to replace Complex script (RTL)
Hebrew fonts, but it wouldn't work. Any suggestion?

Many thanks in advance!

Kdarlaomer
 
M

Mark Tangard

If you want to change the font *only* for digits, use "^#"
(which matches any number) in the .Text line:

With Selection.Find
.Text = "^#"
.Replacement.Text = ""
.Font.Name = "Times New Roman"
.Replacement.Font.Name = "Tahoma"
.Wrap = wdFindContinue
.Forward = True
.Format = True
.MatchCase = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With

However, if you have large numbers and you also want to
include the thousands separators, decimal separators,
currency symbols, etc., it becomes a LOT more complicated.
If that's what you need, post back with a description of
what sorts of number you have and what system you're using
for separators, currency, etc.
 
W

Word Heretic

G'day Mark Tangard <Mark@NoMailPlease_Tangard.com>,

Find: [0-9,.]{1,99} ????



Mark Tangard said:
If you want to change the font *only* for digits, use "^#"
(which matches any number) in the .Text line:

With Selection.Find
.Text = "^#"
.Replacement.Text = ""
.Font.Name = "Times New Roman"
.Replacement.Font.Name = "Tahoma"
.Wrap = wdFindContinue
.Forward = True
.Format = True
.MatchCase = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With

However, if you have large numbers and you also want to
include the thousands separators, decimal separators,
currency symbols, etc., it becomes a LOT more complicated.
If that's what you need, post back with a description of
what sorts of number you have and what system you're using
for separators, currency, etc.

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 
B

Bob S

G'day Mark Tangard <Mark@NoMailPlease_Tangard.com>,

Find: [0-9,.]{1,99} ????

The problem is a little more complicated than that. That pattern finds
every comma and period in the text! The trick is to find things like
those below without picking up other punctuation marks in the
document.

9
9,000
456.567
..00362
9,000.00362

Bob S
 
W

Word Heretic

G'day Bob S <[email protected]>,

I'll include that in Ranger in Heretic.dot. It wont be ready for some
weeks.


Bob S said:
G'day Mark Tangard <Mark@NoMailPlease_Tangard.com>,

Find: [0-9,.]{1,99} ????

The problem is a little more complicated than that. That pattern finds
every comma and period in the text! The trick is to find things like
those below without picking up other punctuation marks in the
document.

9
9,000
456.567
.00362
9,000.00362

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 

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