我希望在VBA中制作宏,将西里尔字母翻译为拉丁语 目前,我使用
List<string> customerNames = new List<string>();
for (int i = 1; i < lines.Length; i++) {
customerNames.Add(data[i][2]);
}
并为所有字母重复。 这种方法有效。但它很慢地适用于大文档,因为更多50次调用Selection.Find.Execute。
问:我能以更快的速度解决问题吗? 例如,像
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Ш" 'cyrillic letter
.Replacement.Text = "Sh" 'latin letter
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
或者我可以用其他方式解决它(Application.ActiveDocument.Characters或Application.ActiveDocument.Words等),而不会丢失格式?
答案 0 :(得分:0)
这就是我要用的:
删除选择并将其设置为范围(如果可能)。
禁用ScreenUpdating,它会更好。
Sub Replacer()
Dim rng1 As Range
call onstart
Set rng1 = Activedocument.Range
With rng1.Find
.Text = "Ш" 'cyrillic letter
.Replacement.Text = "Sh" 'latin letter
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
call onend
End Sub
Public Sub OnEnd()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.StatusBar = False
End Sub
Public Sub OnStart()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
End Sub