Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search the VBA source code with RegEx

Tags:

regex

excel

vba

I need to find all the occurrences of a particular RegEx in my source code (i.e. col*r ). I realized you can programmatically search through your code for patterns (RegEx) if you use the VBComponents.CodeModule.Find() method as it's explained in here and here. But that does not meet my needs as it only tells you whether such expression is found or not. I need the actual expression found in the module as well (e.g. colour and color).

Is there any way to achieve this programmatically within VBA?

like image 645
SMir Avatar asked May 15 '26 07:05

SMir


1 Answers

Dim re, match
Set re = CreateObject("vbscript.regexp")
re.Pattern = "your regex"
re.Global = True

For Each match In re.Execute("you input")
    MsgBox match.Value
Next

for more information check this link:http://msdn.microsoft.com/en-us/library/ms974570.aspx

like image 96
Victor Ribeiro da Silva Eloy Avatar answered May 19 '26 02:05

Victor Ribeiro da Silva Eloy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!