[英]VBA word macro / automatically find and replace specific characters for whole document
I'm trying to do the following using the macro: Upon opening the document, automatically search whole document for brackets {{ }}
and delete them including the text inside.我正在尝试使用宏执行以下操作:打开文档后,自动在整个文档中搜索方括号
{{ }}
并删除它们,包括其中的文本。 It doesn't do the job well, just operates on the text selected, not the whole document.它不能很好地完成这项工作,只是对选定的文本进行操作,而不是整个文档。
Sub SelectToBracketsDelete()
With Selection.Find
.ClearFormatting
.Text = "{{"
.Forward = False
.Wrap = wdFindStop
.Execute
End With
Selection.Extend
With Selection.Find
.Text = "}}"
.Forward = True
.Execute
.Text = ""
End With
Selection.Text = ""
End Sub
Is this what you are looking for?这是你想要的?
Word 2007 -> stackoverflow Word 2007 -> stackoverflow
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "\{\{*\}\}"
.Replacement.Text = ""
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.