I was writing a script for VBA, for Outlook 2013, that uses regular expressions and every example I find seems to use Set regex = New RegExp
to create a RegExp object. When I tried this I got Compile error: User-defined type not defined.
I managed to get regular expressions to work using Set regex = CreateObject("vbscript.regexp")
.
Any reason why the first options is not working?
The VBScript RegExp object matches strings against special text patterns, called regular expressions. The InStr function can be used to search a string to see if it contains another string. The RegExp object provides a far more sophisticated string searching facility by using regular expressions.
Regular Expressions is a sequence of characters that forms a pattern, which is mainly used for search and replace. The purpose of creating a pattern is to match specific strings, so that the developer can extract characters based on conditions and replace certain characters.
RegEx stands for “Regular Expression” in VBA Excel and is a sequence of characters that defines the search pattern for finding a specific pattern of characters in a string of values. In a simple word, “we can create a regular expression pattern and use it to search for the string of that pattern.”
How to start using RegEx. To start using RegEx in VBA, you need to select and activate the RegEx object reference library from the references list. Start by going to the VBA IDE, select Tools –> References, then select Microsoft VBScript Regular Expressions 5.5, then click OK.
Probably only missing some dependencies, meaning some references should be added.
Go to Tools -> References ->
Find & check the "Microsoft VBScript Regular Expressions" (1.0 or 5.5 both work for me).
I know this question was already successfully answered, I just wanted to add a solution that worked for me.
Tools -> References - > "Microsoft VBScript Regular Expressions 5.5"
was already activated.
Set regex = New RegExp
caused a compile error.
Set regex = New VBScript_RegExp_55.RegExp
works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With