2

I want to use a font i.e. Candara for text and at the same time, I want to use some other font for numbers in the text because the number style in the font Candara is somehow disturbing (at least for me). I don't want to change fonts again and again while writing text and numbers.

Is it possible to use Candara font for text and some other font for numbers simultaneously (with out changing font again and again).

1

1 Answer 1

1

This can be done with VBa. Depending on the size of your file (how many words you have) it may be slow.

It also assumes that you only use 2 fonts. If you use other fonts, it will overwrite them!!

It's VBa so remember, save it first to create a back up (there is no undo)

Sub updateFont()

Dim doc As Document
Set doc = ActiveDocument
Dim i As Integer    
For i = 1 To doc.Range.Characters.Count

     If IsNumeric(doc.Range.Characters(i)) Then
        doc.Range.Characters(i).Font.Name = "Algerian"
        Else
        doc.Range.Characters(i).Font.Name = "Verdana"
     End If
Next i

End Sub

Screenshot before (using an italic font) enter image description here

and after

enter image description here

How do I add VBA in MS Office?

8
  • @Dave--"Variable not defined" error raised while compiling your code.
    – maliks
    May 27, 2016 at 13:54
  • But i think Dim i As Integer is missing in your code as I made this change and it worked for me then.
    – maliks
    May 27, 2016 at 14:00
  • I have added a new button for this macro to use for all documents. But I can't see that button, where will I find it ?
    – maliks
    May 27, 2016 at 14:08
  • I'm unable to use macro for other new documents. Why is it so whereas I saved that macro function for all documents. Now here is error that macro security disabled whereas I enabled all macros therefore
    – maliks
    May 27, 2016 at 14:17
  • Each time in each document will I need to run macro code in macro editor ?
    – maliks
    May 27, 2016 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .