Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Brad in Tampa Brad in Tampa is offline
external usenet poster
 
Posts: 1
Default Macro for search and replace not working

I have MS Word 2002. I am trying to create a macro with a search and replace
for Times New Roman size 12 to replace it with Courier New size 10. It works
when creating the macro, but not when I run the macro. And there is no
mention of either font in the VBA (edit). Any ideas?

Thanks,
brad


  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Brad in Tampa[_2_] Brad in Tampa[_2_] is offline
external usenet poster
 
Posts: 1
Default Macro for search and replace not working

Ok, I found a solution. When changing font and size of font in a macro,
don't use search and replace. Instead highlight area and use "Format" and
then "Font" from the toolbar.

"Brad in Tampa" wrote:

I have MS Word 2002. I am trying to create a macro with a search and replace
for Times New Roman size 12 to replace it with Courier New size 10. It works
when creating the macro, but not when I run the macro. And there is no
mention of either font in the VBA (edit). Any ideas?

Thanks,
brad


  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Macro for search and replace not working

The macro recorder does not store the complete range of functions and often
produces rather bulky code. To add font information to a search, you will
have to add it manually eg

Sub ReplaceExample()
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'**********************
.Text = ""
.Font.Name = "Times New Roman"
.Font.Size = "12"
.Replacement.Text = ""
.Replacement.Font.Name = "Courier New"
.Replacement.Font.Size = "10"
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
End With
End Sub

http://www.gmayor.com/installing_macro.htm
--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Brad in Tampa wrote:
I have MS Word 2002. I am trying to create a macro with a search and
replace for Times New Roman size 12 to replace it with Courier New
size 10. It works when creating the macro, but not when I run the
macro. And there is no mention of either font in the VBA (edit).
Any ideas?

Thanks,
brad



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search-and-replace macro never works Liam Gibbs Microsoft Word Help 3 May 8th 07 12:38 AM
Search and Replace Johann Swart Microsoft Word Help 4 September 25th 06 07:53 AM
search and replace macro genius? BobW Microsoft Word Help 1 March 3rd 06 04:40 PM
Search and Replace Jackie Formatting Long Documents 0 October 20th 05 10:23 AM
Search and Replace not working if I select a Format for Heading St Sherrie Deen Microsoft Word Help 0 April 27th 05 08:53 PM


All times are GMT +1. The time now is 05:20 AM.

Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"