C# Snippets
Language_Change
public void Language_Change(ref Word.Document objDocument, string sDocumentType, Word.WdLanguageID enLanguageID)
{
bool bdocumentprotected;
bool blnTrackChangesOn;
Word.Range myStoryRange;
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;
blnTrackChangesOn = objDocument.TrackRevisions;
objDocument.TrackRevisions = blnTrackChangesOn;
if ((modSpecific.Document_IsValidAndProtected(objDocument) == true))
{
bdocumentprotected = true;
modWordObjectModel.Document_Unprotect(objDocument, gsDOCUMENTPASSWORD, false);
}
objDocument.ShowSpellingErrors = true;
foreach (var myStoryRange in objDocument.StoryRanges)
{
myStoryRange.LanguageID = enLanguageID;
while (!(myStoryRange.NextStoryRange == null))
{
myStoryRange = myStoryRange.NextStoryRange;
myStoryRange.LanguageID = enLanguageID;
}
}
objDocument.TrackRevisions = blnTrackChangesOn;
return;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
finally
{
if ((bdocumentprotected == true))
modWordObjectModel.Document_Protect(objDocument, gsDOCUMENTPASSWORD, false);
}
}
Public Sub Language_Change(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String, _
ByVal enLanguageID As Word.WdLanguageID)
Dim bdocumentprotected As Boolean
Dim blnTrackChangesOn As Boolean
Dim myStoryRange As Word.Range
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
blnTrackChangesOn = objDocument.TrackRevisions
objDocument.TrackRevisions = blnTrackChangesOn
If (modSpecific.Document_IsValidAndProtected(objDocument) = True) Then
bdocumentprotected = True
Call modWordObjectModel.Document_Unprotect(objDocument, gsDOCUMENTPASSWORD, False)
End If
objDocument.ShowSpellingErrors = True
For Each myStoryRange In objDocument.StoryRanges
myStoryRange.LanguageID = enLanguageID
Do While Not (myStoryRange.NextStoryRange Is Nothing)
myStoryRange = myStoryRange.NextStoryRange
myStoryRange.LanguageID = enLanguageID
Loop
Next myStoryRange
objDocument.TrackRevisions = blnTrackChangesOn
Exit Sub
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Finally
If (bdocumentprotected = True) Then
Call modWordObjectModel.Document_Protect(objDocument, gsDOCUMENTPASSWORD, False)
End If
End Try
End Sub
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top