Class Language (Word VBA)
The class Language represents a language used for proofing or formatting in Microsoft Word. The Language object is a member of the Languages collection. To use a Language class variable it first needs to be instantiated, for example
Dim lng as Language
Set lng = Languages(Index:=1)
For Each
Here is an example of processing the Language items in a collection.
Dim lng As Language
For Each lng In Languages
Next lng
ActiveGrammarDictionary
Returns a Dictionary object that represents the active grammar dictionary for the specified language.
If there is no grammar dictionary installed for the specified language, this property returns Nothing.
Dim lngLanguage As Long
Dim dicGrammar As Dictionary
lngLanguage = Selection.LanguageID
Set dicGrammar = Languages(lngLanguage).ActiveGrammarDictionary
MsgBox dicGrammar.Path & Application.PathSeparator & dicGrammar.Name
ActiveHyphenationDictionary
Returns a Dictionary object that represents the active hyphenation dictionary for the specified language.
If there is no hyphenation dictionary installed for the specified language, this property returns Nothing.
Dim lngLanguage As Long
Dim dicHyphen As Dictionary
lngLanguage = Selection.LanguageID
Set dicHyphen = Languages(lngLanguage).ActiveHyphenationDictionary
If dicHyphen Is Nothing Then
MsgBox "No hyphenation dictionary installed!"
Else
MsgBox dicHyphen.Path & Application.PathSeparator & dicHyphen.Name
End If
ActiveSpellingDictionary
Returns a Dictionary object that represents the active spelling dictionary for the specified language.
If there is no spelling dictionary installed for the specified language, this property returns Nothing.
Dim lngLanguage As Long
Dim dicSpelling As Dictionary
lngLanguage = Selection.LanguageID
Set dicSpelling = Languages(lngLanguage).ActiveSpellingDictionary
If dicSpelling Is Nothing Then
MsgBox "No spelling dictionary installed!"
Else
MsgBox dicSpelling.Path & Application.PathSeparator _
& dicSpelling.Name
End If
ActiveThesaurusDictionary
Returns a Dictionary object that represents the active thesaurus dictionary for the specified language.
If there is no thesaurus dictionary installed for the specified language, this property returns Nothing.
Dim lngLanguage As Long
Dim dicThesaurus As Dictionary
lngLanguage = Selection.LanguageID
Set dicThesaurus = Languages(lngLanguage).ActiveThesaurusDictionary
If dicThesaurus Is Nothing Then
MsgBox "No thesaurus dictionary installed!"
Else
MsgBox dicThesaurus.Path & Application.PathSeparator _
& dicThesaurus.Name
End If
DefaultWritingStyle
Returns or sets the default writing style used by the grammar checker for the specified language.
This property controls the global setting for the writing style. The name of the writing style is the localized name for the specified language. When setting this property, you must use the exact name found in the Writing style box on the Spelling & Grammar tab in the Options dialog box (Tools menu). The ActiveWritingStyle property sets the writing style for each language in a document. The ActiveWritingStyle setting overrides the DefaultWritingStyle setting.
Dim lngLanguage As Long
lngLanguage = Selection.LanguageID
Msgbox Languages(lngLanguage).DefaultWritingStyle
ID
Returns a number that identifies the specified language. Here you can find possible values for
Selection.LanguageID = Languages("Icelandic").ID
Name
Returns the name of the specified object.
Dim strName As String
strName = Languages(1).Name
NameLocal
Returns the name of a proofing tool language in the language of the user.
MsgBox Languages(wdGerman).NameLocal
MsgBox Languages(wdGerman).Name
SpellingDictionaryType
Returns or sets the proofing tool type. Here you can find possible values for
You can use this property to change the active spelling dictionary to one of the available add-on dictionaries that work with Word. For example, there are legal, medical, and complete spelling dictionaries you can use instead of the standard dictionary. Some of the constants listed above may not be available to you, depending on the language support (U.S. English, for example) that you've selected or installed.
myType = Languages(wdEnglishUS).SpellingDictionaryType
WritingStyleList
Returns a string array that contains the names of all writing styles available for the specified language.
Sub WritingStyles()
Dim WrStyles As Variant
Dim i As Integer
WrStyles = Languages(wdEnglishUS).WritingStyleList
For i = 1 To UBound(WrStyles)
MsgBox WrStyles(i)
Debug.Print WrStyles(i) & " [" & Trim(Str$(i)) & "]"
Next i
End Sub