How can VBA application use the correct built in styles across English and French versions of Windows/Word
Question
I developed a Word 2003 report generation application that extracts data from a database.
Most of the organization uses English versions of Windows and Office. But, many users in our French office use their local versions. If I use any of Word's built-in Heading styles Heading (1-9), the French version expects Titre (1-9).
In my current solution, the user sets a Form option and VBA does the following:
Dim HeadingStyle as String
Dim HeadingLevel as Integer
If ChooseReportFrm.FrenchOpt.Value = True Then
HeadingStyle = "Titre "
Else
HeadingStyle = "Heading "
End If
...
Call InsertText(HeadingStyle & CStr(HeadingLevel))
I would like to make this process automatic and completely transparent to the user. I have been searching in vain for a location-independent way to set the correct style, such as an enumerated constant. Does anybody have any ideas for a more elegant solution?
Solution
Have a look at the WdBuiltinStyle
Enumeration.
When assigning styles, you can do so by their local name (which is what you seem to do now), but you can also use one of the enumeration values, in your case setting the Style
property to WdBuiltinStyle.wdStyleHeading1
would do the trick.
Dim para As Paragraph
Set para = ActiveDocument.Paragraphs(1)
para.Style = WdBuiltinStyle.wdStyleHeading1