Lene Fredborg, DocTools, har hvert år siden 2008 modtaget den prestigefyldte pris som Microsoft Most Valuable Professional (MVP) i Word – link til information om MVP Award'en DocTools - dokumentautomatisering - add-ins, makroer og skabeloner til Microsoft Word (logo) Dokumentautomatisering
Add-ins & Makroer
Skabeloner
Til Microsoft Word
Dokumentautomatisering, skabeloner (templates), add-ins og makroer til Microsoft Word (grafik)



Bogmærk denne side | Tip en ven om DocTools


Søg thedoctools.com:

Custom Search



Word document including macros ready for use...

Updated 10-Feb-2018
Macro – Create List of Local Built-in Style Names

If you are creating a Word document, a template or an add-in that is going to be used on PCs with different language versions of Microsoft Word installed, you need to pay attention to the fact that the names of the built-in styles are language-specific. This article discusses some of the problems that may occur. In addition, you can download a Word document that lets you create a list of the local built-in style names with the click of a button.

Terms of use

You are welcome to use the macros and Word tips provided on this website. The contents is copyright. You may not reproduce any of contents (with or without modification or credits) elsewhere on the web, or on CD. Please link to the contents on this website instead.

Please note that all free Word tips, macros, add-ins and demos are provided "as is" and without obligation. See also detailed Terms of use.


Updated 10-Feb-2018: The document you can download via this article now includes all built-in styles found in Word 2003, Word 2007, Word 2010, Word 2013, and Word 2016 - a total of 375 styles. In addition, I have added information about the different types of styles supported by Word.

Problems with language-specific built-in style names

Problems in relation to STYLEREF fields

STYLEREF fields are often used to repeat e.g. document headings in the document header. This is a great feature. The syntax of the field code is:

{ STYLEREF "name of style" }

See the article STYLEREF fields and language-specific style names for information about the problems that can occur in relation to STYLEREF fields when different language versions of Word are involved and for tips on how you can overcome the problems.

Note that the article linked above explains how you can use alias style names in STYLEREF fields. You can also use alias style names in macros.

Problems in relation to macros

In macros, you may often need code that applies a style or manipulates a style. If you insert the name as a string as shown in the following example, the macro will result in an error if it is executed on a PC with a non-English version of Word installed:

ActiveDocument.Styles("Heading 2").Font.Size = 12

Fortunately, there is a solution to that problem. The WdBuiltInStyle enumeration provides constants for the built-in style names. However, Microsoft developers seem to have forgotten constant names for all new styles added in Word 2007 and later versions (but as shown below, there is also a solution in that situation). In VBA, you should always use the style name constants or the corresponding values. This way, your code will be independent of the installed language version of Word. The code line above would then look as follows:

ActiveDocument.Styles(wdStyleHeading2).Font.Size = 12

In case you need one of the built-in styles for which a name constant is missing, you can use the value instead. Actually, you could also use the value even if a name constant is found but in order to make your code easier to read and understand, I suggest you use the name constants whenever found. All built-in styles have a unique value. All the values are negative. For example, "Heading 2" has value -3. This means that the following code line would give the same result as the code samples above:

ActiveDocument.Styles(-3).Font.Size = 12

About the Word document ready for download

In order to make it easy to create a list of the local built-in style names, I have created a Word document you can download via the link below. The document contains a pre-completed 10-column table that includes the following for each built-in style – a total of 375 styles are included:

  • The VBA style name constant (example: wdStyleBodyText)
  • The corresponding VBA style name value (example: -67)
  • Information about in which version of Word the style is found - covers Word 2003, Word 2007, Word 2010, Word 2013, Word 2016
  • The type of style (Paragraph, Character, List, Table)
  • The English style name (example: Body Text)
  • An empty cell for the local style name – automatically filled in when you click a button in the document (see below)

The document contains a couple of macros that can be executed via buttons in the document. Click one button and all local styles names will automatically be filled in. Another button lets you clear the local style names.

The 375 built-in styles are spread across:

  • 96 Paragraph styles
  • 28 Character styles
  • 4 List styles
  • 247 Table styles

You will find more details about the different style types below.

104 new styles were added in Word 2013 - they were all table styles! In Word 2016, 4 new paragraph styles have been added. The total amount of built-in table styles is huge compared to other types of styles, especially when taking into consideration that only a small part of Word users care about Table styles.

The illustration below shows page 1 of the Word document including the instruction, the buttons and the top of the table:

Part of page 1 of the Word document with the style list

Follow the instructions in the document. Please note that you need to enable macros when you open the document in order to be able to use the functionality in the document. The previous version of the document was in .doc format. The updated version is in .docm format which means it cannot be used in Word 20013. The macros have been tested in Word 2007 and later versions, including Word 2016.

If you do not have access to the language version of Word for which you want to retrieve the styles names, you may send a copy of the document to somebody who has that version installed and ask him/her to run the macro, save the document and return it to you. Alternative, you may download and install the desired language pack (previously, you would have to pay for extra language packs but they are free for Word 2016).

The illustration below shows part of the table filled with Danish style names in column 10 (red font). Green color in a cell in columns 3-7 means that the style in that row is found in the Word version in question (Word 2003, Word 2007, Word 2010, Word 2013, Word 2016):

Part of page 1 of the Word document with the style list



About the different style types in Word

The document you can download via the link above includes information about the style type for each built-in style.

When you create a new style via the user interface in Word, you can select from the style types listed in the leftmost column below.

In column 2, the VBA constant for that type of style is shown (WdStyleType Enumeration). Column 3 shows the value corresponding to the constant.

When checking for styles of a specific type in VBA, you can use either the constant or the value. Examples:

If ActiveDocument.Styles(XXX).Type = wdStyleTypeParagraph then

or

If ActiveDocument.Styles(XXX).Type = 1 then

As for the style names, your code will be easier to read and understand if you use the constants instead of the values.

Style type
in user interface

VBA constant

Value

Available
Word 2003-2016

Paragraph

wdStyleTypeParagraph

1

All Word versions

Character

wdStyleTypeCharacter

2

All Word versions

Table

wdStyleTypeTable

3

All Word versions

List

wdStyleTypeList

4

All Word versions

 

wdStyleTypeParagraphOnly

5

Added in Word 2007

Linked (paragraph and character)

wdStyleTypeLinked

6

Added in Word 2007

 

What are the differences between wdStyleTypeParagraph, wdStyleTypeParagraphOnly and wdStyleTypeLinked?

The user interface of Word does not include a style type option corresponding to wdStyleTypeParagraphOnly.

The following three lines of VBA code adds three styles of different types:

ActiveDocument.Styles.Add _
Name:="StyleType Paragraph", Type:=wdStyleTypeParagraph

ActiveDocument.Styles.Add _
Name:="StyleType ParagraphOnly", Type:=wdStyleTypeParagraphOnly

ActiveDocument.Styles.Add _
Name:="StyleType Linked", Type:=wdStyleTypeLinked

In the Styles Task Pane in Word, the three styles will look as follows:

The difference between wdStyleTypeLinked, wdStyleTypeParagraph and wdStyleTypeParagraphOnly

There appears to be no difference between the styles created as wdStyleTypeParagraph and wdStyleTypeLinked. They both appear with the symbol consisting of a Pilcrow and an a: ¶a.

The style of the type wdStyleTypeParagraph appears with the Pilcrow symbol only, ¶.

Styles that have the combined ¶a symbol can be applied to either entire paragraphs or be used as character styles, i.e. applied to part of a paragraph only. However, it is only possible to use such style as a character style if the option Disable Linked Styles at the bottom of the Styles Task Pane is unchecked. I recommend checking that option in general to prevent paragraph styles from being used as character styles. The makes it easier to keep a clean and consistent formatting.

If checking the style type, via VBA, of the three styles added above, the results are as follows:

Activedocument.Styles("StyleType Linked").Type
RETURNS 1 (i.e. style type wdStyleTypeParagraph)

Activedocument.Styles("StyleType Paragraph").Type
RETURNS 1 (i.e. style type wdStyleTypeParagraph)

Activedocument.Styles("StyleType ParagraphOnly").Type
RETURNS 1 (i.e. style type wdStyleTypeParagraph)

But .Linked returns values corresponding to the type shown in the Styles Task Pane, regardless of whether Disable Linked Styles is on or off:

Activedocument.Styles("StyleType Linked").Linked
RETURNS True

Activedocument.Styles("StyleType Paragraph").Linked
RETURNS True

Activedocument.Styles("StyleType ParagraphOnly").Linked
RETURNS False

 

What does style inspection > Reveal Formatting show?

If checking the three styles via Styles Task Pane > Inspection > Reveal Formatting, all three styles appear as Paragraph styles.

Built-in styles cannot be deleted

If you create a new blank document in Word and check which styles are found in the document, e.g. in the Organizer dialog box (can be opened via Developer tab > Document Template > Organizer button), you may only see:

  • Default Paragraph Font
  • No List
  • Normal
  • Table Normal

But if you paste the following line in the Immediate window in the Visual Basic Editor and press Enter:

?ActiveDocument.Styles.Count

you will see a large number, e.g. 372 in case of Word 2016. This means that the document contains all those styles but they don't appear in e.g. the Organizer list unless they have been in use.

  • A style has been in use once it has been applied to text in the document. Once it has been set in use, it will remain so no matter whether no content uses the style anymore. In VBA, you can check whether a style is/has been in use:

    Activedocument.Styles(XXX).InUse

  • You can apparently delete built-in styles, e.g. via the Organizer dialog box. But note that the styles are not deleted - it just looks as if they have been deleted. If you check the count of styles again, you will see the same number as before. Also, if you try to apply a built-in style you just deleted, e.g. via VBA or by typing its name in the Apply Styles dialog box and clicking Apply, you will see that the style is applied. It has not been deleted!


Related information

Via the link below, you can download a PDF document that contains the style names of almost 140 built-in styles in English, Danish, German and French (the style list does not include styles added in Word 2013 and Word 2016):

Word Style Names in English, Danish, German, French.

See also the article STYLEREF fields and language-specific style names.




Top of page

Back to Macros...

BulletADD-INS Word add-ins ready for use - work smarter in Word





Copyright © 2006-2018 Lene Fredborg – DocTools ApS – alle rettigheder forbeholdt | Microsoft Word skabeloner (templates) – add-ins – VBA makroer | Spar tid og arbejd mere effektivt i Microsoft Word
Privat politik | Betingelser for brug | Om cookies | Bogmærk denne side | Tip en ven | Links | Kontakt