Consulting

Results 1 to 10 of 10

Thread: Use of Wildcards in Word Find

  1. #1
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location

    Use of Wildcards in Word Find

    I am using Word2003. I have not been able to get the "#" wildcard (single digit) to work in any wildcard use, e.g., Like, Find, etc. All other wildcard representations including groups and other neat stuff seems to work OK.

    Is this unique to my implementation of Word2003 or are others experiencing this problem as well?
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Try "?" instead of "#"
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by Oorang
    Try "?" instead of "#"
    Thanks for the reply.

    "?" is the wildcard for any character or digit so "?" does not accomplish what "#" is supposed to do. Assume I am looking for three characters followed by a dash and then 3 numbers, e.g., ABC-123. The search sequence should be "???-###". But if I use "???-???", that will find ABC-123, but it would also find ABC-DEF which is not what I want. The work around is to use "???-???" and then test that the last 3 characters are numeric. That is my current workaround, but per any documentation I have seen, Word is supposed to support "#"
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  4. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    Not sure if I follow... Are you looking for any/every sequence or do you know any part of what you're looking for? I was thinking that if you know with certainty some part of what you're looking for, you could find it, expand the range to obtain the whole sequence, convert the range to a string variable and then simply evaluate the string. Just a thought. Dave

  5. #5
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by Dave
    Not sure if I follow... Are you looking for any/every sequence or do you know any part of what you're looking for? I was thinking that if you know with certainty some part of what you're looking for, you could find it, expand the range to obtain the whole sequence, convert the range to a string variable and then simply evaluate the string. Just a thought. Dave
    In the particular case that prompted this thread, I am looking for a sequence that is a combination of alpha, numerics and special characters. Thanks for the reply. You are correct that your approach is possible and that is exactly what I am doing as a workaround. But, if "#" worked as it was supposed to, the extra effort (expanding the range, converting the range, testing for numeric section, etc) would not be required.

    I can always find workarounds; my real question is if others have found that "#" did not seem to work. If so, I will stop trying to get it to work each time I have a new application
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  6. #6
    VBAX Regular
    Joined
    Aug 2004
    Location
    On a 100 acre hobby farm in beautiful west Quebec.
    Posts
    87
    Location
    I think you may be confusing the wildcard codes with a different application. To look for the pattern ABC-123, I would use a Find what pattern like this instead:

    ([A-Z]{3,})(-)([0-9]{3,})

    This specifically looks for any 3 uppercase alphabetic characters followed by a hyphen and any 3 digits.
    Eric

    Experience is not what happens to a man; it is what a man does with what happens to him. ? Aldous Huxley

  7. #7
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by EricFletcher
    I think you may be confusing the wildcard codes with a different application. To look for the pattern ABC-123, I would use a Find what pattern like this instead:

    ([A-Z]{3,})(-)([0-9]{3,})

    This specifically looks for any 3 uppercase alphabetic characters followed by a hyphen and any 3 digits.
    thanks for the reply. You are correct that your pattern will find what I am looking for and it is certainly a way to do it. I should have taken that approach rather than the work around I am using.

    That said, if you use VBA help to explore the Find, Like and similar procedures and then explore Wildcards, the "#" is clearly stated as a wildcard for a single digit (0-9).
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  8. #8
    VBAX Regular
    Joined
    Aug 2004
    Location
    On a 100 acre hobby farm in beautiful west Quebec.
    Posts
    87
    Location
    Quote Originally Posted by MWE
    That said, if you use VBA help to explore the Find, Like and similar procedures and then explore Wildcards, the "#" is clearly stated as a wildcard for a single digit (0-9).
    I've never checked that (in part because VBA's Help doesn't work properly on my system), but it does seem odd. Without wildcards, a ^# pattern in Word's Find will look for a single digit, but certainly not without the carat. Perhaps the # on its own is only valid for use in VBA's Find or Like statements.

    Word's Help has a list of the various wildcard options, but it isn't very clear, and there are much better resources online.
    Eric

    Experience is not what happens to a man; it is what a man does with what happens to him. ? Aldous Huxley

  9. #9
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    It should work as documented. Could you give an example of it not working as expected?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  10. #10
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi folks,

    FWIW, the find string can be simplified to:
    ???-[0-9]{3,3}
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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