Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Using Regular Expressions with VBA

I have done a fair bit of scripting with javascript and php and am learning
VBA.

Is it possible to use regular expressions in VBA / Excel in such a way that
other users can open a workbook and the regular expressions will work without
them having to download mrefunc.xll or to alter the Tools / References list
in the VBA editor.

Looks to me like the answer is no but thought I would ask.

Andrew
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Using Regular Expressions with VBA

Andrew,
If you use early binding, you can set a reference to "MS VBScript Regular
Expression x.x". The reference is associated with the workbook so the user
will not to change it, assuming:
- that reference, or a later version, is available on the system
- scripting has not been disabled, by Admin/Policy

Then
Dim mRegEx As RegExp

If you mean the above may be problematic, then use late binding and trap the
error. so no reference is set and

Dim mRegEx As Object
Set mRegEx = CreateObject("VBScript.RegExp")

If mRegEx Is Nothing Then
MsgBox "Could create RegExp object"
End If

NickHK

"Andrew Hall NZ" wrote in message
...
I have done a fair bit of scripting with javascript and php and am

learning
VBA.

Is it possible to use regular expressions in VBA / Excel in such a way

that
other users can open a workbook and the regular expressions will work

without
them having to download mrefunc.xll or to alter the Tools / References

list
in the VBA editor.

Looks to me like the answer is no but thought I would ask.

Andrew



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Using Regular Expressions with VBA


That sounds very promising, thanks, where can I read something about binding.

Andrew
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Using Regular Expressions with VBA

Andrew,
Take your pick :
http://www.google.co.uk/search?hl=en...e+Search&meta=

NickHK

"Andrew Hall NZ" wrote in message
...

That sounds very promising, thanks, where can I read something about

binding.

Andrew



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Using Regular Expressions with VBA

Here is a simple example that validates email addresses.

'-----------------------------------------------------------------
Public Function ValidEmail(Adress As String) As Boolean
'-----------------------------------------------------------------
Dim oRegEx As Object
Set oRegEx = CreateObject("VBScript.RegExp")
With oRegEx
.Pattern = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
' .Pattern = "^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$"
ValidEmail = .Test(Adress)
End With
Set oRegEx = Nothing
End Function


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Andrew Hall NZ" wrote in message
...

That sounds very promising, thanks, where can I read something about

binding.

Andrew





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Using Regular Expressions with VBA

Thank you both for your replies, all is working fine. It can be pretty
frustrating working with a new language, being able to ask questions makes
all the difference.

Andrew
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get rid of with regular expressions Howdy Excel Discussion (Misc queries) 1 January 18th 10 07:42 PM
Regular expressions in VB FiluDlidu Excel Discussion (Misc queries) 4 March 21st 08 01:10 AM
Regular expressions JeffMelton Excel Programming 2 March 1st 06 12:52 AM
Regular Expressions in VBA? Rob[_23_] Excel Programming 13 February 10th 05 05:34 AM
VBA and Regular expressions Friedrich Muecke Excel Programming 3 October 3rd 03 01:46 AM


All times are GMT +1. The time now is 04:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"