none
How to check if a font is already set as the default font RRS feed

  • Question

  • Hi Support,

    I am trying to set Times New Roman size 12 as the default font, but before setting the default font, first I want to determine if the current default font is already to set to following font settings/properties.

        With ActiveDocument.Styles(wdStyleNormal).Font

            .Name = "Times New Roman"

            .Size = 12

            .Bold = False

            .Italic = False

            .Underline = wdUnderlineNone

            .UnderlineColor = wdColorAutomatic

            .StrikeThrough = False

            .DoubleStrikeThrough = False

            .Outline = False

            .Emboss = False

            .Shadow = False

            .Hidden = False

            .SmallCaps = False

            .AllCaps = False

            .Color = wdColorAutomatic

            .Engrave = False

            .Superscript = False

            .Subscript = False

            .Spacing = 0

            .Scaling = 100

            .Position = 0

            .Kerning = 0

            .Animation = wdAnimationNone

            .Ligatures = wdLigaturesNone

            .NumberSpacing = wdNumberSpacingDefault

            .NumberForm = wdNumberFormDefault

            .StylisticSet = wdStylisticSetDefault

            .ContextualAlternates = 0

        End With

    I figured out the following code on how to check for .Name and .Size, but I don't know how to check for all the font properties. Any help, will be appreciated. Thanks

    Dim Mystyle As Object

    Set Mystyle = ActiveDocument.Styles(wdStyleNormal).Font

    If Mystyle.Name = "Times New Roman" And Mystyle.Size = 12 Then

        MsgBox "Default font already set toTimes New Roman"

        Exit sub

    Else

        MsgBox "Set Times New Roman 12 with all default properties as default font"

    End If

    End Sub

    Sunday, May 17, 2015 5:41 AM

Answers

  • Hi Fox245,

    >> I figured out the following code on how to check for .Name and .Size, but I don't know how to check for all the font properties.

    If you want to check whether the current font is default font, I think you need to compare the property of the font one by one. For example, if you want to check the Bold property, the code as below:

           If Mystyle.Name = "Times New Roman" And Mystyle.Size = 12 And Mystyle.Bold = False Then
                MsgBox "Default font already set toTimes New Roman"
                Exit Sub
            Else
                MsgBox "Set Times New Roman 12 with all default properties as default font"
            End If

    If you want to check other properties, you need to add them to if statement.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by Fox245 Monday, May 18, 2015 1:43 PM
    Monday, May 18, 2015 9:52 AM

All replies

  • Hi Fox245,

    >> I figured out the following code on how to check for .Name and .Size, but I don't know how to check for all the font properties.

    If you want to check whether the current font is default font, I think you need to compare the property of the font one by one. For example, if you want to check the Bold property, the code as below:

           If Mystyle.Name = "Times New Roman" And Mystyle.Size = 12 And Mystyle.Bold = False Then
                MsgBox "Default font already set toTimes New Roman"
                Exit Sub
            Else
                MsgBox "Set Times New Roman 12 with all default properties as default font"
            End If

    If you want to check other properties, you need to add them to if statement.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by Fox245 Monday, May 18, 2015 1:43 PM
    Monday, May 18, 2015 9:52 AM
  • Thanks Edward. I was considering the same thing you suggested, but I thought it was clumsy if I use an IF STATEMENT with a bunch of logical ANDs, so I wondered if there is a better way to verify the default font and it's properties.  Any way thank you for your help with this.

    Monday, May 18, 2015 1:43 PM