I did lot of Googling to get a proper answer on how to use or start using Regular Expressions in VBA.
At last I got it so I'd like to share my knowledge with you guys. Please correct me if I am wrong.
I did lot of Googling to get a proper answer on how to use or start using Regular Expressions in VBA.
At last I got it so I'd like to share my knowledge with you guys. Please correct me if I am wrong.
By default Regular Expression option is disabled in word 2007, to enable that plase do following steps,
1). Go to Tools > References as shown below.
2). Now put a tick on "Microsoft VBScript Regular Expressions 5.5" option and then press oh as shown below.
3). Now onward you can create a RegExp object in your VBA script. You can verify it be searching in object data base as explained below. View > Object Browser ( Or press F2) , as shown below.
and search for RegExp object
4). The RegExp object uses regular expressions to match a pattern. The following properties are provided by RegExp. These properties set the pattern to compare the strings that are passed to the RegExp instance:
a. Pattern: A string that defines the regular expression.
b. IgnoreCase: A Boolean property that indicates whether you must test the regular expression against all possible matches in a string.
c. Global: Sets a Boolean value or returns a Boolean value that indicates whether a pattern must match all the occurrences in a whole search string, or whether a pattern must match just the first occurrence.
RegExp provides the following methods to determine whether a string matches a particular pattern of a regular expression:
d. Test: Returns a Boolean value that indicates whether the regular expression can successfully be matched against the string.
e. Execute: Returns a MatchCollection object that contains a Match object for each successful match.
Please find a simile example for RexExp provided in Microsoft msdn forum.
I hope it might help full for some one, because i wasted almost half a day on it.
Thanks