G
Guest
Can anyone tell me how to test if a given string is a valid macro name?
Thank you.
Sprinks
Thank you.
Sprinks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Chip Pearson said:Try a function like
Function IsValidProcName(ProcName As String) As String
' reference to "Microsoft VBScript Regular Expressions 5.5
Dim Pattern As String
Dim RExp As VBScript_RegExp_55.RegExp
Set RExp = New VBScript_RegExp_55.RegExp
Pattern = "^[A-Za-z]+[A-Za-z0-9_]*$"
RExp.Pattern = Pattern
IsValidProcName = RExp.Test(ProcName)
End Function
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
Sprinks said:Can anyone tell me how to test if a given string is a valid macro name?
Thank you.
Sprinks
Tom Ogilvy said:You would have to write code to read all the information in the modules and
parse out the macro names.
A start is here:
http://www.cpearson.com/excel/vbe.htm
Or you might try something like this:
Sub AAA()
s = "MyMacro"
On Error Resume Next
Application.Run s
If Err.Number <> 0 Then
MsgBox s & " is not a macro name or there is an error in the macro"
Else
MsgBox "OK"
End If
On Error goto 0
End Sub
whether the string is a valid name or not.
Sprinks said:Chip,
Thank you for your response.
I'm afraid I don't understand your code, but in any case, it returns True
whether the string is a valid name or not.
??
Sprinks
Chip Pearson said:Try a function like
Function IsValidProcName(ProcName As String) As String
' reference to "Microsoft VBScript Regular Expressions 5.5
Dim Pattern As String
Dim RExp As VBScript_RegExp_55.RegExp
Set RExp = New VBScript_RegExp_55.RegExp
Pattern = "^[A-Za-z]+[A-Za-z0-9_]*$"
RExp.Pattern = Pattern
IsValidProcName = RExp.Test(ProcName)
End Function
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
Sprinks said:Can anyone tell me how to test if a given string is a valid macro name?
Thank you.
Sprinks
Chip Pearson said:I'm afraid I don't understand your code, but in any case, it returns True
whether the string is a valid name or not.
I thought you meant a syntactically valid procedure name, not necessarily
the name of an existing procedure. My mistake. The code I posted only tests
whether the procedure name is allowable by VBA syntax, not whether the
procedure actually exists.
Regular Expressions are a method of testing whether a given text value
matches a pattern. The pattern I used,
^[A-Za-z]+[A-Za-z0-9_]*$
tests for a beginning of string (^), followed by one or more charcters in
the range A-Z (upper or lower case), followed be zero or more characters in
the range A-Z a-z 0-9 or an underscore, followed by and end of string ($).
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
Sprinks said:Chip,
Thank you for your response.
I'm afraid I don't understand your code, but in any case, it returns True
whether the string is a valid name or not.
??
Sprinks
Chip Pearson said:Try a function like
Function IsValidProcName(ProcName As String) As String
' reference to "Microsoft VBScript Regular Expressions 5.5
Dim Pattern As String
Dim RExp As VBScript_RegExp_55.RegExp
Set RExp = New VBScript_RegExp_55.RegExp
Pattern = "^[A-Za-z]+[A-Za-z0-9_]*$"
RExp.Pattern = Pattern
IsValidProcName = RExp.Test(ProcName)
End Function
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
Can anyone tell me how to test if a given string is a valid macro name?
Thank you.
Sprinks
Mais, malheuresement, il marche tropWant to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.