Sub SelectAllText()
Dim rng As Range
Dim found As Boolean
found = False
'遍历文档内容查找@1
For Each rng In ActiveDocument.StoryRanges
With rng.Find
.Text = "@1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceNone
End With
'如果找到@1,将其选中并设置标志位为True
If rng.Find.Found Then
rng.Select
found = True
End If
Next rng
'如果未找到@1,给出提示信息
If Not found Then
MsgBox "未找到@1"
End If
End Sub
使用以下VBA代码在Word中查找“@1”并将其选中。此代码将查找并选中当前Word文档中所有的“@1”。
最新推荐文章于 2024-09-28 12:46:54 发布