0

I spent a bit of time looking for a solution to set the font at a given selection to "+Headings" as shown in the screenshot below. This is useful if one would later want to change the theme of the document and make sure that the font defined for Headings and Body are properly changed on the selection which font was programaticlaly changed.

Font Drop down showng +headings and +body style fonts

For instance, using Selection.font.name = "Calibri", would set the font to "Calibri" but not have it set as "Calibri (Headings)"

4

1 回答 1

0

I was able to solve this (setting to '+Headings' font) by using the following:

    Selection.Font.name = ActiveDocument.Styles("Heading 1").Font.name
    Selection.Font.NameAscii = ActiveDocument.Styles("Heading 1").Font.NameAscii
    Selection.Font.NameBi = ActiveDocument.Styles("Heading 1").Font.NameBi
    Selection.Font.NameFarEast = ActiveDocument.Styles("Heading 1").Font.NameFarEast
    Selection.Font.NameOther = ActiveDocument.Styles("Heading 1").Font.NameOther

It seems that also using:

    Selection.Font.name = "Calibri"
    Selection.Font.NameAscii = "+headings"

To set the font to "+Body", one could use:

    Selection.Font.name = ActiveDocument.Styles("Normal").Font.name
    Selection.Font.NameAscii = ActiveDocument.Styles("Normal").Font.NameAscii
    Selection.Font.NameBi = ActiveDocument.Styles("Normal").Font.NameBi
    Selection.Font.NameFarEast = ActiveDocument.Styles("Normal").Font.NameFarEast
    Selection.Font.NameOther = ActiveDocument.Styles("Normal").Font.NameOther

It seems that also using:

    Selection.Font.name = "Arial"
    Selection.Font.NameAscii = "+body"

NOTE: This assumes that you have not customized your 'Heading 1' or 'Normal' style to use a different font.

于 2020-09-28T10:33:28.407 回答