当前位置: 代码迷 >> VBA >> word vba find 怎么匹配0个或多个前面的字符
  详细解决方案

word vba find 怎么匹配0个或多个前面的字符

热度:5939   发布时间:2013-02-26 00:00:00.0
word vba find 如何匹配0个或多个前面的字符
我想同时匹配 ac, abc, abbc, abbbc ....

ab@c不能匹配0个b
ab{0,}c似乎不合法

有办法查找一次,匹配这样的字符串吗?

------解决方案--------------------------------------------------------
又写了一段不使用VBScript的,直接使用Word VBA内置功能的,楼主试一下:
VB code
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 WithEnd Sub
  相关解决方案