|
发表于 2023-2-26 09:38
来自手机
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub Word中查找指定字符串()
Dim strText As String
Dim intPos As Integer
Dim intStart As Integer
Dim strFind As String
Dim i As Integer
strFind = "街道办"
'查找文中内容
strText = ActiveDocument.Range.Text
intStart = 1
Do
intPos = InStr(intStart, strText, strFind)
If intPos > 0 Then
MsgBox strFind & "出现在第 " & intPos & " 位,结束位置是第 " & intPos + Len(strFind) - 1 & " 位"
intStart = intPos + 1
Else
Exit Do
End If
Loop
'查找批注中的内容
For i = 1 To ActiveDocument.Comments.Count
strText = ActiveDocument.Comments.Item(i).Range.Text
intStart = 1
Do
intPos = InStr(intStart, strText, strFind)
If intPos > 0 Then
MsgBox strFind & "出现在第 " & i & " 条批注中的第 " & intPos & " 位,结束位置是第 " & intPos + Len(strFind) - 1 & " 位"
intStart = intPos + 1
Else
Exit Do
End If
Loop
Next
MsgBox "查找完毕"
End Sub |
评分
-
1
查看全部评分
-
|