我正在使用VBA在Word文档上运行一个查找和替换。我遇到的问题是通配符不支持字符的"0或1次出现“。文档中有表单的标签,它的形式是:{##**$$}}和。根据特定项目的不同,标记之间的内容要么保留,要么删除。但是,如果发现/替换存在的话,我也希望它能删除一个新行。通配符表达式"|" & tagname & "|*|End" & tagname & "|" & vbCr不工作,因为它显式地要求换行符在末尾。
有干净的替代品吗?
发布于 2022-11-04 01:36:49
经过一些实验,我找到了一种更好的方法:
'find text without considering newline
Do While Selection.Find.Execute(FindText:=x)
'if next character after selection is newline:
If Selection.Next(unit:=wdCharacter) = Chr(13) Then
'expand selection by one character
Selection.MoveEnd unit:=wdCharacter, count:=1
End If
ran.Delete
Loop发布于 2022-06-03 23:10:26
尝试:
"|" & tagname & "|*|End" & tagname & "[|^13]{1,}"https://stackoverflow.com/questions/72485979
复制相似问题