D
David Turner
I have a macro (based on code fragments largely lifted from this forum) to
set the language in all story ranges via the wd languageId code entered in an
input box. Is there any way to arrange for this code to become the default
the next time the macro is run so that the user does not have to change it
each time (from 1033 to 1036 say)? In general, a user is likely to work in
only one language. The code could be hard-wired but then you would need a
different version for each language.
Thanks.
David
Option Explicit
Sub LanguageIDInputBox()
'See http://msdn.microsoft.com/en-us/library/bb213877.aspx for languageIDs
Dim rngStory As Range
Dim Message, Title, Default
Dim MyLanguage
Dim lngJunk As Long
Dim oShp As Shape
' Define the message.
Message = "Enter WdLanguageID code i.e. wdEnglishUK (2057) wdFrench
(1036)"
Title = "Language InputBox" ' Defines the Title.
Default = "1033" ' Defines default value.
' Displays the message, the title and the default value
MyLanguage = InputBox(Message, Title, Default)
If MyLanguage = "" Then
MsgBox ("Nothing entered. Exiting routine.")
Exit Sub
End If
'Fix the skipped blank Header/Footer problem
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
'Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
If rngStory.Words.Count = 1 Then GoTo SetnextRange
Do
rngStory.LanguageID = MyLanguage
On Error Resume Next
Select Case rngStory.StoryType
Case 6, 7, 8, 9, 10, 11
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then
rngStory.LanguageID = MyLanguage
End If
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
DoEvents
SetnextRange:
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
StatusBar = "Resetting language"
Loop Until rngStory Is Nothing
Next
StatusBar = "Language reset"
'Clean up
Set rngStory = Nothing
End Sub
set the language in all story ranges via the wd languageId code entered in an
input box. Is there any way to arrange for this code to become the default
the next time the macro is run so that the user does not have to change it
each time (from 1033 to 1036 say)? In general, a user is likely to work in
only one language. The code could be hard-wired but then you would need a
different version for each language.
Thanks.
David
Option Explicit
Sub LanguageIDInputBox()
'See http://msdn.microsoft.com/en-us/library/bb213877.aspx for languageIDs
Dim rngStory As Range
Dim Message, Title, Default
Dim MyLanguage
Dim lngJunk As Long
Dim oShp As Shape
' Define the message.
Message = "Enter WdLanguageID code i.e. wdEnglishUK (2057) wdFrench
(1036)"
Title = "Language InputBox" ' Defines the Title.
Default = "1033" ' Defines default value.
' Displays the message, the title and the default value
MyLanguage = InputBox(Message, Title, Default)
If MyLanguage = "" Then
MsgBox ("Nothing entered. Exiting routine.")
Exit Sub
End If
'Fix the skipped blank Header/Footer problem
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
'Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
If rngStory.Words.Count = 1 Then GoTo SetnextRange
Do
rngStory.LanguageID = MyLanguage
On Error Resume Next
Select Case rngStory.StoryType
Case 6, 7, 8, 9, 10, 11
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then
rngStory.LanguageID = MyLanguage
End If
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
DoEvents
SetnextRange:
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
StatusBar = "Resetting language"
Loop Until rngStory Is Nothing
Next
StatusBar = "Language reset"
'Clean up
Set rngStory = Nothing
End Sub