Replace para font 'Tahoma' with 'Verdana'

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Replace para font 'Tahoma' with 'Verdana'

Post by Robie »

Hi

I have documents with mixture of styles and fonts. I need to replace all Tahoma font based paras with Verdana. The find/replace works (inline sort of) but the macro generated from it doesn't. Any idea how I can do this? The slighly modified code is below:

Code: Select all

Sub replaceTahomaWithVerdana()
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ""
        .Font.Name = "Tahoma"                                                ' I added this
        .Replacement.Text = ""
        .Replacement.Font.Name = "Verdana"                            ' and this line
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .matchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Thanks

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Replace para font 'Tahoma' with 'Verdana'

Post by HansV »

The code seems to work OK when I try it, I'd only change

.Wrap = wdFindAsk

to

.Wrap = wdFindStop

What exactly is the problem you encounter?
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Replace para font 'Tahoma' with 'Verdana'

Post by Robie »

HansV wrote:The code seems to work OK when I try it, I'd only change

.Wrap = wdFindAsk

to

.Wrap = wdFindStop

What exactly is the problem you encounter?
Thanks for the reponse Hans. I changed ask to stop but still no difference, i.e. it *doesn't* do any replacements at all. I know I have lots of paras with Tahoma font & I keep my cursor on one such para but it doesn't change. In fact no replacements at all.

BTW: An aside question: Is it possible to change the underlying font of the styles in a macro? That is, go thu all styles replacing the default font to Verdana if it is Tahoma!

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Replace para font 'Tahoma' with 'Verdana'

Post by HansV »

No idea why it doesn't work for you. Here is a macro to replace the font in styles:

Code: Select all

Sub ReplaceInStyles()
  Dim sty As Style
  For Each sty In ActiveDocument.Styles
    If sty.Font.Name = "Tahoma" Then
      sty.Font.Name = "Verdana"
    End If
  Next sty
End Sub
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Replace para font 'Tahoma' with 'Verdana'

Post by Robie »

HansV wrote:No idea why it doesn't work for you. Here is a macro to replace the font in styles:

Code: Select all

Sub ReplaceInStyles()
  Dim sty As Style
  For Each sty In ActiveDocument.Styles
    If sty.Font.Name = "Tahoma" Then
      sty.Font.Name = "Verdana"
    End If
  Next sty
End Sub
Thanks Hans for the style code - so simple.

The other replacement of font just doesn't work for me. I guess, I will have to come back to it when I am bit fresh.

Thanks again.