Skip to content

Instantly share code, notes, and snippets.

@dspinellis
Last active August 7, 2023 02:27
Show Gist options
  • Save dspinellis/63e13c4f4873b8945242f022ff22f7d1 to your computer and use it in GitHub Desktop.
Save dspinellis/63e13c4f4873b8945242f022ff22f7d1 to your computer and use it in GitHub Desktop.
Old Microsoft Word Greek document fixer
'
' Old Microsoft Word Greek document fixer
'
' Copyright 2023 Diomidis Spinellis
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.
'
' Fix a Word 6.0 file, also known as Word 97-2003 or .doc file,
' where Greek characters are represented by the Unicode character of
' each cp-1250 (extended Latin) character residing in the same 8-bit position
' as the Greek character in cp-1253.
' (Originally this worked by having fonts that had Greek glyphs in the
' positions of the Latin glyphs.)
'
' To use this program perform the following in Microsoft Word:
' - Press Alt+F11 to open the VBA editor.
' - In the VBA editor, select Insert -> Module to create a new module.
' - Paste this macro code into the module.
' - Close the VBA editor.
' - Press Alt+F8, select GreekFix, and click "Run".
Sub GreekFix()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchCase = True
.Wrap = wdFindContinue
End With
' Replace characters in the regular positions
For i = 184 To 254
ReplaceOneChar ChrW(i), ChrW(i + 720)
Next i
' In cp-1253 capital letter alpha with stress has a non-regular position,
' because it clashed with the Word's paragraph mark.
ReplaceOneChar ChrW(162), ChrW(902)
End Sub
Sub ReplaceOneChar(c1 As String, c2 As String)
With Selection.Find
.Text = c1
.Replacement.Text = c2
.Execute Replace:=wdReplaceAll
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment