5,139
社区成员
发帖
与我相关
我的任务
分享
Sub 查找零个以上指定字符()
Dim i As Integer
Dim strfind As String
Dim IsB As Boolean
Selection.HomeKey unit:=wdStory
With Selection.Find
.Text = "a*c"
.MatchWildcards = True
.Execute Forward:=True
Do While .Found
strfind = Mid(Selection.Text, 2, Len(Selection.Text) - 2)
IsB = True
For i = 1 To Len(strfind)
If strfind = "" Then MsgBox Selection.Text: Exit For
If Mid(strfind, i, 1) <> "b" Then IsB = False: Exit For
Next i
If IsB Then MsgBox Selection.Text
Selection.EndKey unit:=wdLine
.Execute
Loop
End With
End Sub
Sub 查找零个以上字符()
'添加对VBScript Regular Expression的引用
Dim myRegExp As New VBScript_RegExp_55.regexp
Dim str As String
Dim match As Object, matches As Object
str = ActiveDocument.Content
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "ab{0,}c"
Set matches = myRegExp.Execute(str)
For Each match In matches
MsgBox match
Next match
End Sub