PDA

View Full Version : [SOLVED:] Getting a special style to inherit the Normal style language ID using VBA



Roderick
02-04-2018, 01:59 AM
I deal a lot with multi-lingual templates and in one of these I have a style called "Special" which always seems to inherit the language ID of the last one it dealt with. On the other hand the Normal style always 'behaves' itself and uses the correct language selected for it.

What I want to do is write a procedure so that the "Special" style inherits the one set in the Normal style.

My research through Google came up with a few answers but none matched what I needed. Nevertheless, one came quite close by inheriting the font name of the Normal style.

Here is the code:

Public Sub InheritNormalStyle()


Dim oStyle As Style
Set oStyle = ActiveDocument.Styles("Special")
oStyle.Font.Name = oStyle.BaseStyle.Font.Name


'oStyle.LanguageID = oStyle.BaseStyle.LanguageID.Name


End Sub


The font name line works well and you will see I've tried, in the last line, to follow the principle for what I thought might work in the same way for the language ID but it gives me an error when I try to run the procedure.

Can anyone suggest the correct syntax to achieve this, please?

Thanks

Roderick

gmayor
02-04-2018, 03:55 AM
I would have thought that the style would already have the language of the style it was based on, but if not


Dim oStyle As Style
Dim oBase As Style
Dim lngLanguage As Long
Set oStyle = ActiveDocument.Styles("Special")
Set oBase = oStyle.BaseStyle
lngLanguage = oBase.LanguageID
oStyle.LanguageID = lngLanguage

Roderick
02-04-2018, 10:06 AM
Thanks, Graham.

It works beautifully! Now I can see where I was going wrong.

Regards

Roderick