Thread: [Solved] Macro for microsoft Word
View Single Post
 
Old 05-27-2012, 02:43 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
I want to create macro which will find Cyrillic alphabet and replace it to Roman
OK. At last you've said what it is you want to do.

As there is more than one Cyrillic alphabet (26, actually, see: http://en.wikipedia.org/wiki/Cyrilli...#Summary_table), you'd need to clarify which one you want to convert also. Then there is the problem of what each character should be converted to. For example, I have no idea what 'ж' should be represented as.

According to the 'Romanization' discussion here (http://en.wikipedia.org/wiki/Cyrilli...t#Romanization) there are also at least seven different systems for Romanizing the Cyrillic alphabet. You would have to choose the systme that suits your needs.

If you pick a simple Romanization system, it might require nothing more that a sequential Find/Replace operation in which each Cyrillic character (or a group of Cyrillic chracters) is replaced with one or more Roman characters. If that's all you require, a simple Word table could be used to hold the Find/Replace character list. For that, create a suitable two-column table with the Cyrillic chracters in the first column and the Roman characters in the second, add the following macro to the document, then run it. All you'll need to do is to select the document to process when prompted by the macro.
Code:
Sub Romanize()
Application.ScreenUpdating = True
Dim i As Long, Rng As Range, FRTbl As Table
If Application.Dialogs(wdDialogFileOpen).Show <> -1 Then Exit Sub
If ActiveDocument = ThisDocument Then Exit Sub
Set FRTbl = ThisDocument.Tables(1)
For i = 2 To FRTbl.Rows.Count
  With ActiveDocument.Range.Find
    .ClearFormatting
    Set Rng = FRTbl.Rows(i).Cells(1).Range
    Rng.End = Rng.End - 1
    .Text = Rng.Text
    .Replacement.ClearFormatting
    Set Rng = FRTbl.Rows(i).Cells(2).Range
    Rng.End = Rng.End - 1
    .Replacement.Text = Rng.Text
    .MatchWholeWord = False
    .MatchCase = False
    .Wrap = wdFindStop
    .Execute Replace:=wdReplaceAll
  End With
Next
Set FRTbl = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote