我正在尝试创建一个 VB 脚本,它将执行 word 文档中某些字符的替换,我通过以下方式进行管理:
objSelection.Find.Text = "["
objSelection.Find.Forward = TRUE
objSelection.Find.Replacement.Text = "q"
objSelection.Find.Execute ,,,,,,,,,,2
objSelection.Find.Text = "{"
objSelection.Find.Forward = TRUE
objSelection.Find.Replacement.Text = "w"
objSelection.Find.Execute ,,,,,,,,,,2
objSelection.Find.Text = "^"
objSelection.Find.Forward = TRUE
objSelection.Find.Replacement.Text = "y"
objSelection.Find.Execute ,,,,,,,,,,2
objSelection.Find.Text = "~"
objSelection.Find.Forward = TRUE
objSelection.Find.Replacement.Text = "z"
objSelection.Find.Execute ,,,,,,,,,,2
objSelection.Find.Text = "]"
objSelection.Find.Forward = TRUE
objSelection.Find.Replacement.Text = "x"
objSelection.Find.Execute ,,,,,,,,,,2
objSelection.Find.Text = "}"
objSelection.Find.Forward = TRUE
objSelection.Find.Replacement.Text = "ć"
objSelection.Find.Execute ,,,,,,,,,,2
objSelection.Find.Text = "@"
objSelection.Find.Forward = TRUE
objSelection.Find.Replacement.Text = "]"
objSelection.Find.Execute ,,,,,,,,,,2
但是,我设法做到的方式非常慢,尤其是当文本文件为几 MB 时增加需要替换的字符数时...因此,脚本会为每个替换字符遍历整个文档结果是脚本的执行速度非常慢。是否有可能在一个word文档中并行更改几个字符,脚本只有一个通过文档并根据遇到的字符来执行替换?我还尝试将 word 文档中的逐行加载到变量中,并将每个字符与给定字符进行比较以进行替换,从而导致脚本执行速度变慢...对不起我的英语,我希望我能成功解释我的问题。请帮我。谢谢你。:)