word vba 通配符 删除不匹配的部分
以下是使用通配符删除不匹配部分的Word VBA示例代码:
Sub RemoveNonMatchingText() Dim myPattern As String myPattern = "Matching*" Selection.Find.ClearFormatting With Selection.Find .Text = myPattern .Forward = True .Wrap = wdFindContinue .MatchWildcards = True .Execute Do While .Found ' Do nothing .Execute Loop End With End Sub
在上面的代码中,myPattern变量包含通配符模式,例如“Matching*”,它将匹配任何以“Matching”开头的文本。然后,使用Selection.Find对象在文档中查找匹配项,并使用MatchWildcards属性启用通配符匹配。最后,找到匹配项后,可以通过执行任何所需的操作来删除或更改不匹配的部分
原文地址: https://www.cveoy.top/t/topic/cJOt 著作权归作者所有。请勿转载和采集!