Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA Regular Expression (Word 2003/VBA)

    I need a Word/VBA macro using a regular expression to find any number of any length found between the tags <U></U>.

    Thank you in advance for your replies.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA Regular Expression (Word 2003/VBA)

    You can use something like this:
    <code>
    With Selection.Find
    .ClearFormatting
    .Format = False
    .Text = "<U>*</U>"
    .MatchWildcards = True
    If .Execute Then
    ...
    End If
    End With
    </code>
    The backslashes before < and > are needed because < and > have special meanings in a wildcard search. The tells Word to interpret < and > as literal characters.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: VBA Regular Expression (Word 2003/VBA)

    If you only want to find NUMBERS in between these two tags then you should use the wildcard search string
    <code><U>[0-9]@</U></code>
    as your search string.

    This assumes that your definition of a number only includes digits, if you want to allow numbers like 1,432 or 0.25 as well then we will need to do something different.

    StuartR

  4. #4
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Regular Expression (Word 2003/VBA)

    Thank you both for the suggestions.

    Using your suggestions, here is the macro used to find numbers between html underline tags.

    Sub FindNumbersBetweenUnderlineTags()
    '
    ' FindNumbers Macro
    '
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "<U>[0-9]@</U>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute
    End Sub

    Thank you again for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •