1
我正在搜索文檔中的特定文本,刪除文本,然後添加分節符。我只能得到這個代碼爲一個實例工作。當我嘗試一個while while循環時,檢查每一行,Word崩潰。Word 2010 VBA:搜索文本並用分節符替換
With Selection.Find
.Text = "INSTRUCTOROVERVIEW"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.InsertBreak Type:=wdSectionBreakNextPage