2

I would like to revisit this question - Remove setting from style to inherit setting from base style - since the answer provided and voted doesn't really do what I want it to do.

A style in Word can inherit various properties from the style on which it was based. However changing any property of the new style breaks the inheritance, i.e. changes to the base style are not propagated to the child style. I would like a way, probably via a VBA macro, to re-establish the inheritance.

The method from the preferred answer from the previous question, linked above, succeeds in setting the font name to be the same as that for the base style, but does not re-establish the inheritance link. Further changes to the parent do not update the child.

How can I re-establish that inheritance link?

Many thanks

2 Answers2

1

I haven't tried it with every style setting, but at least for a few settings (font size and spacing after so far), simply changing the setting of the child style to match the parent will re-establish the inheritance.

Mark
  • 26
0

TL;DR: Edit the XML definition of the style.

Setting the value to the BaseStyle value is a one-time fix, not something that restores inheritance. The values are explicitly set to the values of the base style, BUT not to inherit.

Example: Char style C1 is based on the defaults of para style List Number 2. LN2 is based on Normal. Normal font is Calibri 11 pt black. Open C1 and you see its font & size are blank. Change to Arial 10 and it's now forever an explicit value. Run the macro and C1 is set back to Calibri 11 pt black - not blank (inherited)! Change LN2 and C1 stays Calibri 11 pt black - not LN2's font and size. I haz a sad.

From an XML perspective, style grrr has w:color set to green. Its base style has 11 pt text

<w:style w:type="character" w:customStyle="1" w:styleId="grrr">
    <w:name w:val="grrr"/>
    <w:basedOn w:val="DefaultParagraphFont"/>
    <w:uiPriority w:val="1"/>
    <w:qFormat/>
    <w:rsid w:val="009014C2"/>
    <w:rPr>
        <w:color w:val="00B050"/>
    </w:rPr>
</w:style>

Note w:sz is not defined.

After a manual change to 8 pts the XML appears as such: <w:sz w:val="16"/>

After use of the .BaseStyle macro above, it is explicitly set to 11 pts in the XML: <w:sz w:val="22"/>

That's not inheritance. That's explicit setting to the value of the base style.

Manual removal of <w:sz w:val="22"/> from the XML restored inheritance. And that is a ridiculous solution.

In the UI, we see the font size is 11 pts. That's the same value as the base style, and was set using the BaseStyle approach, but it's the same as manually setting it to 11. enter image description here

When I change the base style, text formatted using Asset Title doesn't change. There's no inheritance - it's just 11 pts.

After editing docname.docx\word\styles.xml (without linearizing!) to remove <w:sz w:val="22"/> we see inheritance has been restored - the font size control is empty, which is Word's way of telling us the value is inherited.

enter image description here

When I change the base style, text formatted using Asset Title changes. There's inheritance - it's 11 pts because its parent is 11 pts.

Neman
  • 390
  • 1
  • 2
  • 13