Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default Why vbscript examples do not work?

The function below works as intended.

However, I get a syntax error when I try to replace "Set re =
CreateObject..." with

Set re = New regexp

and when I try to eschew the Set statement altogether and replace "Dim re"
with

Dim re as New regexp

The syntax error is "user-defined type not define".

Both erroneous forms appear in the examples at
http://msdn.microsoft.com/en-us/library/ms974570.aspx .

Why don't the examples?

I suspect I need to attach a reference (Tools References). If so, which
reference?

Alternatively, are the examples written for an incompatible revision of
Excel/VB? If so, which one?

I am using Excel 2003 with VB 6.3 as part of Office 2003 and Win XP SP3.

Is the function, as written below, compatible with the VB with Excel 2007?


The function....


Function extractNumber(s As String, n As Integer)
Dim re, nums
extractNumber = ""
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\d+"
Set nums = re.Execute(s)
If nums.Count = n Then extractNumber = --nums.Item(n - 1)
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Why vbscript examples do not work?

If using VB Script regular expressions, you need to add a reference as follows:
Tools References Microsoft VB Script Regular Expressions
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default Why vbscript examples do not work?

"arjen van..." wrote:
If using VB Script regular expressions, you need to add a reference as
follows:
Tools References Microsoft VB Script Regular Expressions


Klunk! I went looking for exactly that, but overlooked it ... until you
mentioned it. Thanks.

And now I do see this statement on the web page
http://msdn.microsoft.com/en-us/library/ms974570.aspx :

"To run this code, you can [...] copy it to VB (need to add references to
Microsoft VBScript Regular Expressions)". Double klunk!


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
Unable to get examples to work for lookup etc BrandonC Excel Worksheet Functions 6 July 20th 06 02:58 AM
about examples hassan barjini New Users to Excel 1 November 2nd 05 11:08 AM
Looking for Userform examples - site on web, download examples thom hoyle Excel Programming 1 May 10th 05 05:23 PM
Tutorials with examples Hervet Excel Programming 1 January 7th 05 06:29 PM
RunAutoMacros does not work correctly from vbscript! Juha Vehvilainen Excel Programming 2 January 3rd 04 02:11 AM


All times are GMT +1. The time now is 04:42 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"