0
votes

I'm having an issue with some character style that doesn't reflect the style change when applied (this doesn't happen always): Example: I have a character style for italics, and when I apply the character style, the word still appears as normal (but the char style is applied, and checking the properties, the style has the check ok for italics).
In order to fix this, I select the word with the issue, right click on the style and use the option "Update [StyleName] to match selection", and it displays the italics correctly.

The problem here is that when I try to replicate this behavior with a VBA Macro (via recording macro), the macro that Word writes has this error: Run-time error '5900': The property is not allowed for character styles. This is the line with error:

ActiveDocument.Styles("StyleItalic").AutomaticallyUpdate = False

Looking at the code created via Macro, seems that it is not possible for a character style to be automatically updated.

The character style is also created via macro, and I can't see anything wrong in the style:

Private Sub Creo(style As String, fontName As String, fontSize As Integer, hasItalic As Boolean)
        On Error Resume Next
        Selection.ClearFormatting
        ActiveDocument.Find.style = ActiveDocument.Styles(style)
        ActiveDocument.Find.Execute
        If ActiveDocument.Find.Found = False Then
            ActiveDocument.Styles.Add name:=style, Type:=wdStyleTypeCharacter
            ActiveDocument.Styles(style).QuickStyle = True
            ActiveDocument.Styles(style).font.Size = fontSize
            ActiveDocument.Styles(style).font.name = fontName
            ActiveDocument.Styles(style).font.Italic = hasItalic
        End If
End Sub

Is there a way to fix this? Hope I explain myself. I am working with 1000+ pages Word Document, so this becomes a bit too tedious for manual editing. Also, sometimes the style in other word works ok, but other doesn't. (All the words have both paragraph style and character style)

Thanks!

1
Your problem description suggests you're trying to apply the character Style to a part of a paragraph whose underlying Style has the same attribute, but for which the paragraph Style's formatting has been overridden with some other format.macropod

1 Answers

0
votes

Your question describes two unrelated issues.

  1. Applying a character style with the same property as the underlying paragraph style will cause that property to be turned off in the text. Updating the character style to match the selection will have the opposite effect to what you want.

    To demonstrate: in a new document type a paragraph of text and apply a style that is defined as italic, e.g. Quote or Intense Quote. Select the whole paragraph and press Ctrl+I to turn off italics. Now select just part of the text and apply the character style named Emphasis. You will see that it has no apparent effect on the text. This is because both the paragraph style and the character style are italic, cancelling each other out and having the same effect as turning italics off manually.

    Now right click on Emphasis and select Update to Match Selection. The selected text will now be italic but, as the text preview in the Quick Styles gallery will show you, Emphasis is no longer italic.

  2. Only paragraph and linked styles have the Automatically Update property, which is why you get an error when attempting to set it on a character style.