我目前正在使用Excel搜索基于起始和结束字符的可识别字符串的整个单词文档。中间的字符会有所不同。起始字符将始终为< <,结尾的字符总是>>。示例< <要删除的文本>>。我试图找到所有这些实例并删除它们,包括< < >>字符。下面是我目前的代码,它可以删除连续文本,但是当我尝试添加星号来指定<和<之间的任何内容时,它不再有效。查找基于开始/结束字符变量内部字符在Word文档中的字符串并替换
我相信它不承认*为'任何',但我不知道如何更新以允许。任何帮助表示赞赏!
Sub AddRemoveWatermark(blWatermarkAction As Boolean, blDeleteText As Boolean, strInitialIdentifier As String, strEndingIdentifier As String)
'Word Variables
Dim wrdApplication As Word.Application
Dim wrdDocument As Word.Document
Dim wrdSection As Word.section
Dim strPath As String
Dim lngCount As Long
' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show
Set wrdApplication = New Word.Application
' Display paths of each file selected
For lngCount = 1 To .SelectedItems.Count
strPath = .SelectedItems(lngCount)
Set wrdDocument = wrdApplication.Documents.Open(strPath)
wrdApplication.Visible = True
'Delete all starting << and ending >>
With wrdDocument.Range.Find
.ClearFormatting
.Text = strInitialIdentifier & "*" & strEndingIdentifier
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
'.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Replacement.ClearFormatting
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
End With
Next lngCount
End With
End Sub
我不知道这个问题是否应该注明的副本[这个问题](http://stackoverflow.com/q/7408485/6535336) – YowE3K
如果我读了其他问题/回答正确,它的声音就像你可能想要一串'[\\ <]{2}[!\>] @ [\>] {2}'。 – YowE3K
我试过,作为一个字符串,它不匹配或找到任何东西。我阅读并解释了你引用的文章,看起来你会根据他们的逻辑是正确的,但它没有返回任何与.Text为“[\ <]{2}[!\>] @ [\>] {2}”的例子。“ – Allen