Share via

preventing arbitrary style renaming

Anonymous
2013-01-08T01:49:16+00:00

I'm running into a problem where Word renames styles.

Steps to reproduce:

  1. Create a blank document.
  2. Create a style named "potato". Give it a distinctive look.
  3. Create a style named "Potato". Give it a distinctive look.
  4. Create a style named "title". All lowercase. This is important because there already is a style named "Title" (starting with a capital "T") provided by Word. (It does not appear to be in Normal.dot... so I don't know where it comes from exactly.) Give it a distinctive look too.
  5. Apply each of the 3 styles you've just created *and* the "Title" style to some spans of text in your document. (I type "potato" "Potato" "title" "Title", one word per line, and apply to each word the style of the same name.)
  6. Save the file.
  7. Close the file.
  8. Open the file.

At this point, the styles you created will all be the same as in your original file, *except* that "title" will have been renamed "Title1." This can be verified by going to the span of text to which you originally applied the "title" style and checking the name of the style, which will be "Title1." On the other hand, the "potato" style is not renamed "Potato1".

I'd like to find a way to prevent Word from renaming the "title" style to "Title1."

What I'm describing here is narrowed down to the essentials. I ran into this problem while using a template that I cannot change, with style names that I cannot change either. So using a style name other than "title" is not possible.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2013-01-08T13:18:07+00:00

    [The quoting function does not do what I want; using double quotes + italics to mark block quotes.]

    "Some styles, such as Normal, Heading 1 through Heading 9 and Title (there are more) are built into Word. They can be modified on a template-by-template and document-by-document basis, but not deleted.Since there cannot be two styles with the same name, Word has to rename a newly created style with the same name as a built-in style."

    [Emphasis added.]

    I have to point out that when you say "same name" you must mean "names that are case-insensitively the same", so that "title" and "Title" would be considered "same" and consequently require "title" to be renamed to "Title1".

    Thank you for the suggestion but what you suggest here cannot be true, for the following reasons:

    1. Word will happily work with the styles "potato", "Potato", "title" and "Title" until I save the file, close it and reopen it. So in fact there can be two styles with the "same name" in Word, that is, until I try to save the file.
    2. Word is able to work with styles name "potato" and "Potato" without any problem whatsoever even after saving, closing and reopening the file.

    Moreover, if two styles with the same name were not possible, I'd expect Word to prevent this at the time of style creation. In other words, Word should prevent me from creating "title" in the first place since "Title" already exists and there cannot be two styles of the same name.

    (Venturing a guess here: Word is designed to work with styles named "title" and "Title" without any problem but there is a bug in the code which writes files to disk.)

    *"As an alternative, you could modify and use the built-in Title style instead of creating a new one."*No,  I can't. As I said in my question, what I'm presenting is narrowed down to the essentials of the problem. There are external constraints that are outside my control. I can't change the template from which the style came from because it is under the control of an external entity, and I am not in a position to require them to change anything. The names of the styles matter because the file is eventually going to be processed on the basis of the style names and "title" is not "Title".

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-01-08T14:29:34+00:00

    The VB evidence you bring up is enlightening. But if I try with:

    Selection.Style = "potato"

    and

    Selection.Style = "Potato"

    and both styles exist, then VB will select the proper style, i.e. it will pay attention to case. It seems the VB logic is something like "if there is no case-sensitive match on the style name, then search for a name which matches case-insensitively." This is the kind of behavior I'd expect if styles used to be case-insensitive through and through but newer versions of Word are moving to a case-sensitive model. It would also explain why the GUI accepts names that differ only due to case.

    Given the VB evidence, what you suggest, copy the formatting of "tile" to "Title", might work. There would be only one style with the name "Title" (irrespective of case), and thus code looking for "title" would find "Title". I hope nothing is going to blow up somewhere down the processing line.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. HansV 462.6K Reputation points
    2013-01-08T13:54:39+00:00

    I think it's the other way round: the developers intended style names to be treated case insensitively, and it's a bug that you can create different styles "potato" and "Potato".

    But I admit that I have no proof for this.

    When you assign a style to text using VBA, the lines

    Selection.Style = "Heading 1"

    and

    Selection.Style = "heading 1"

    have the same effect: both assign the built-in style "Heading 1" to the text. This also holds for custom styles: if you create a style named "tomato", but not a style named "TomaTo", the line

    Selection.Style = "TomaTo"

    assigns the "tomato" style to the text, you don't get an error message that "TomaTo" doesn't exist.


    Even if you can't modify the template, you can still modify styles in documents based on the template - or have the styles been locked against editing?

    Was this answer helpful?

    0 comments No comments
  4. HansV 462.6K Reputation points
    2013-01-08T06:49:44+00:00

    Some styles, such as Normal, Heading 1 through Heading 9 and Title (there are more) are built into Word. They can be modified on a template-by-template and document-by-document basis, but not deleted. Since there cannot be two styles with the same name, Word has to rename a newly created style with the same name as a built-in style.

    As an alternative, you could modify and use the built-in Title style instead of creating a new one.

    Was this answer helpful?

    0 comments No comments