我目前正在使用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