我在VBA中有一个用于MS Word 2010的宏。它将哈萨克字母从西里尔字母转换为拉丁字母(有些带有急性字母)。我通过将包含VBA代码模块的文件(.docm文件)合并到MS Word的全局模板(normal.dotm)中来使用它。在我的计算机和其他一些计算机上都可以正常运行,但是在其他一些计算机上,它无法转换某些字符,例如“Ғ”或“Ң”。
Sub KazLat()
'Replacing All Cyrillic Characters to Latin
Dim i As Integer
Dim sKaz As Variant
Dim sLat As Variant
Dim a As String
Dim b As String
a = "I" & ChrW(221)
b = "i" & ChrW(253)
Dim rDoc As Range
Set rDoc = ActiveDocument.Range
'List of Cyrillic Characters
sKaz = Array(an array of kazakh letters in cyrillic. I am not showing it here
because it gets corrupted)
'List of Latin Characters
sLat = Array("A", "a", ChrW(193), ChrW(225), "B", "b", "V", "v", "G", "g",
ChrW(500), ChrW(501), "D", "d", "E", "e", "Io", "io", "J", "j", "Z", "z",
"I", "i", "I", "i", "K", "k", "Q", "q", "L", "l", "M", "m", "N", "n",
ChrW(323), ChrW(324), "O", "o", ChrW(211), ChrW(243), "P", "p", "R", "r",
"S", "s", "T", "t", ChrW(221), ChrW(253), "U", "u", ChrW(218), ChrW(250),
"F", "f", "H", "h", "H", "h", "Ts", "ts", "Ch", "ch", "Sh", "sh", "Sh", "sh",
"", "", "Y", "y", "I", "i", "", "", "E", "e", a, b, "Ia", "ia")
'No screen update while code is running
Application.ScreenUpdating = False
With rDoc.Find
'Replacing cyrillic characters to latin characters
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = False
.Format = True
.MatchCase = True
For i = LBound(sKaz) To UBound(sLat)
.Text = sKaz(i)
.Replacement.Text = sLat(i)
.Execute Replace:=wdReplaceAll
Next i
End With
'Updating screen
Application.ScreenUpdating = True
End Sub
只需要知道我需要在代码中修复的内容,这样它就可以在装有MS Word的所有计算机上工作。