看看this是否为使用python实现word自动化提供了一个开端。
打开文档后,可以执行以下操作。
在执行以下代码后,可以关闭文档并打开另一个文档。Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "test"
.Replacement.Text = "test2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
上述代码将文本“test”替换为“test2”,并执行“replace all”。
根据需要,可以将其他选项设置为true/false。
学习这一点的简单方法是使用要执行的操作创建宏,请参见生成的代码,并在自己的示