Click here to Skip to main content
15,796,989 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the language id of Word dynamically and assign it to Custom Dictionaries language id. I can do this when I know the language the Word is using Word.WdLanguageID.wdEnglishUS;. But how to get this dynamically. I tried as below but get a casting error. I can do this easily in VB6 but need a solution in c#.

Cannot implicitly convert type 'Microsoft.Office.Core.MsoLanguageID' to 'Microsoft.Office.Interop.Word.WdLanguageID'


oCustDict.LanguageSpecific = true;
oCustDict.LanguageID = WordApp.Language;

VB6 - Works

Dim lCurrentLanguage As Long
CurrentLanguage = WordApp.Language
oCustDict.LanguageSpecific = True
oCustDict.LanguageID = lCurrentLanguage
Updated 21-Jul-15 9:12am

1 solution

VB6 was notoriously bad at enforcing variable types - it would jump through invisible hoops to try to stuff data of one type into a variable of a different type, often incorrectly.

C# is much stricter about type conversions, and in 99.9% of cases that's a good thing. In this particular case, it looks like the two enums have the same values, so you just need to add an explicit cast:
oCustDict.LanguageID = (Microsoft.Office.Interop.Word.WdLanguageID)WordApp.Language;
Share this answer
Guru16 23-Jul-15 6:43am    
Excellent! Thank you soo much!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900