将一些拉丁字母改为西里尔字母

时间:2013-06-01 10:00:20

标签: vba ms-word

我需要为MS Word 2010编写一个宏,它会将一些拉丁字母改为Cyrillic:

U+0079 : LATIN SMALL LETTER Y
U+0065 : LATIN SMALL LETTER E
U+0061 : LATIN SMALL LETTER A
U+0070 : LATIN SMALL LETTER P
U+006F : LATIN SMALL LETTER O

分别:

U+0443 : CYRILLIC SMALL LETTER U (hex=443 -> dec=1091)
U+0435 : CYRILLIC SMALL LETTER IE (hex -> dec=1077)
U+0430 : CYRILLIC SMALL LETTER A (hex -> dec=1072)
U+0440 : CYRILLIC SMALL LETTER ER (hex -> dec=1088)
U+043E : CYRILLIC SMALL LETTER O (hex -> dec=1086)

我的宏:

Sub replacement()

Dim zmiana(5, 1) As String
Dim iter As Integer
iter = 0
zmiana(0, 0) = "y"
zmiana(0, 1) = Chr(1091)
zmiana(1, 0) = "e"
zmiana(1, 1) = Chr(1077)
zmiana(2, 0) = "a"
zmiana(2, 1) = Chr(1072)
zmiana(3, 0) = "p"
zmiana(3, 1) = Chr(1088)
zmiana(4, 0) = "o"
zmiana(4, 1) = Chr(1086)

Do Until (iter > 4)
    Selection.Find.ClearFormatting
    Selection.Find.replacement.ClearFormatting
    With Selection.Find
        .Text = replace(iter, 0)
        .replacement.Text = replace(iter, 1)
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute replace:=wdReplaceAll
    iter = iter + 1
Loop
End Sub

调试器停在Chr(1091),但我想不出这个或其他方式的解决方案......

2 个答案:

答案 0 :(得分:4)

您必须使用ChrW替换每个Chr。

答案 1 :(得分:1)

    Sub cir()
'
' cir Macro
'

'
Selection.Replace What:=ChrW(68) & ChrW(382), Replacement:=ChrW(1039), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(68) & ChrW(122), Replacement:=ChrW(1039), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(68) & ChrW(381), Replacement:=ChrW(1039), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(68) & ChrW(90), Replacement:=ChrW(1039), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(76) & ChrW(106), Replacement:=ChrW(1033), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(76) & ChrW(74), Replacement:=ChrW(1033), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(78) & ChrW(106), Replacement:=ChrW(1034), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(78) & ChrW(74), Replacement:=ChrW(1034), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(68) & ChrW(106), Replacement:=ChrW(1026), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(68) & ChrW(74), Replacement:=ChrW(1026), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(65), Replacement:=ChrW(1040), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(66), Replacement:=ChrW(1041), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(67), Replacement:=ChrW(1062), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(268), Replacement:=ChrW(1063), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(262), Replacement:=ChrW(1035), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(68), Replacement:=ChrW(1044), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(272), Replacement:=ChrW(1026), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(69), Replacement:=ChrW(1045), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(70), Replacement:=ChrW(1060), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(71), Replacement:=ChrW(1043), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(72), Replacement:=ChrW(1061), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(73), Replacement:=ChrW(1048), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(74), Replacement:=ChrW(1032), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(75), Replacement:=ChrW(1050), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(76), Replacement:=ChrW(1051), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(77), Replacement:=ChrW(1052), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(78), Replacement:=ChrW(1053), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(79), Replacement:=ChrW(1054), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(80), Replacement:=ChrW(1055), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(82), Replacement:=ChrW(1056), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(83), Replacement:=ChrW(1057), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(352), Replacement:=ChrW(1064), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(84), Replacement:=ChrW(1058), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(85), Replacement:=ChrW(1059), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(86), Replacement:=ChrW(1042), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(90), Replacement:=ChrW(1047), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(381), Replacement:=ChrW(1046), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(100) & ChrW(382), Replacement:=ChrW(1119), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(100) & ChrW(122), Replacement:=ChrW(1119), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(108) & ChrW(106), Replacement:=ChrW(1113), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(110) & ChrW(106), Replacement:=ChrW(1114), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(100) & ChrW(106), Replacement:=ChrW(1106), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(269), Replacement:=ChrW(1095), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(273), Replacement:=ChrW(1106), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(97), Replacement:=ChrW(1072), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(98), Replacement:=ChrW(1073), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(99), Replacement:=ChrW(1094), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(263), Replacement:=ChrW(1115), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(100), Replacement:=ChrW(1076), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(101), Replacement:=ChrW(1077), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(102), Replacement:=ChrW(1092), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(103), Replacement:=ChrW(1075), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(104), Replacement:=ChrW(1093), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(105), Replacement:=ChrW(1080), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(106), Replacement:=ChrW(1112), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(107), Replacement:=ChrW(1082), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(108), Replacement:=ChrW(1083), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(109), Replacement:=ChrW(1084), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(110), Replacement:=ChrW(1085), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(111), Replacement:=ChrW(1086), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(112), Replacement:=ChrW(1087), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(114), Replacement:=ChrW(1088), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(115), Replacement:=ChrW(1089), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(353), Replacement:=ChrW(1096), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(116), Replacement:=ChrW(1090), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(117), Replacement:=ChrW(1091), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(118), Replacement:=ChrW(1074), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(122), Replacement:=ChrW(1079), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:=ChrW(382), Replacement:=ChrW(1078), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False




End Sub