Consulting

Results 1 to 6 of 6

Thread: Local name for built-in styles

  1. #1

    Local name for built-in styles

    Three users in one of my client offices have different versions of Word 2016: one in English, one in French and the other is a Spanish one. Microsoft changes the names of the built-in styles depending on the language used. For this project I need to identify the local name of Heading 1 depending on the template being used in each language.

    I've seen them in the list of styles for each template: English is, obviously, "Heading 1"; French is "Titre 1" and Spanish it is "Título 1". What I need to do now, depending on the language version of Word users are working with, is to identify what is the local name for that heading using the ".NameLocal" VBA designation.

    I have tried various combinations of using .NameLocal but all I keep getting are errors in its construction syntax. After that I need to strip out the '1' of Heading 1 and just use its designation. Would a '.Left' statement do the trick here?

    Thanks for any help.

    Roderick

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I think if you use the Word Style enumeration values, it should work for different languages

    https://docs.microsoft.com/en-us/office/vba/api/word.wdbuiltinstyle


    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Paul_Hossler View Post
    I think if you use the Word Style enumeration values, it should work for different languages
    You can also use the corresponding Word Style constants. For example, "Heading 1"; "Titre 1", and Título 1" are all wdStyleHeading1.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Thanks to both of you for the above replies.

    I used the following code and it gave me the name of wdStyleHeading1 for the active document:
    Dim myStyle As String
    myStyle = ActiveDocument.Styles(wdStyleHeading1)
    Just what was needed.

    Now I have two questions relating to this:
    1. Should the code be referring to the ActiveDocument or should it be the template to which the active document refers?

    2. Having found that in my English version of Word, it says that it is 'Heading 1', how can I now extract the first word from the string to only use 'Heading'? I have searched the net for string functions in Word VBA but cannot find a suitable answer to resolve the problem.

    I appreciate all the help and guidance.

    Roderick

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Roderick View Post
    I used the following code and it gave me the name of wdStyleHeading1 for the active document:
    Dim myStyle As String
    myStyle = ActiveDocument.Styles(wdStyleHeading1)
    You could reduce that to:
    Dim myStyle As String
    myStyle = wdStyleHeading1
    or, if you're only using that one Style anywhere:
    Const myStyle As String = wdStyleHeading1
    Quote Originally Posted by Roderick View Post
    1. Should the code be referring to the ActiveDocument or should it be the template to which the active document refers?
    The above code revision will work with either. You need only use code like ActiveDocument.Styles(wdStyleHeading1) or ActiveDocument.AttachedTemplate.Styles(wdStyleHeading1) if there is a need to differentiate between them for some reason or need to know their 'local' names.
    Quote Originally Posted by Roderick View Post
    2. Having found that in my English version of Word, it says that it is 'Heading 1', how can I now extract the first word from the string to only use 'Heading'? I have searched the net for string functions in Word VBA but cannot find a suitable answer to resolve the problem.
    It's not apparent why you'd need to know what a part of a Style is called in a given language. But, as that seems to be a concern, you could use code like:
    MsgBox Split(ActiveDocument.Styles(wdStyleHeading1).NameLocal, " ")(0)
    or:
    MsgBox Split(ActiveDocument.Styles(myStyle).NameLocal, " ")(0)
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    Very grateful to you, Paul for answering those questions. Those were items I couldn't fathom out.

    The reason I asked about a given part of a style name was something a client had posed to me and I thought I better see if there was an answer. I didn't know about the SPLIT command.

    Thanks again.

    Roderick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •