View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy[_8_] Doug Glancy[_8_] is offline
external usenet poster
 
Posts: 63
Default validation if a string is a proper function's name

I don't think Tim's suggestions will quite work because some chars - like
"/" or "?" are not allowed. Also the length is limited to 31 chars.

I think a good way is to just test it by attempting to add a dummy module
with the name and surrounding the attempt with "On Error Goto Next" and "On
Error Goto 0".

You probably know this, but for XL XP and later you'll also have to test
whether "Trust Access to the Visual Basic Project" is allowed under
ToolsMacroSecurityTrusted Publishers. So, test for that first.

hth,

Doug

"MiM" wrote in message ...
Uzytkownik "JP" napisal w wiadomosci
ps.com...
How about something like this? Select your cells first, then run. It's
a simple loop to check a list of cells against a list of reserved
words.

Sub CheckFunctionNameError()
Dim cell as Range

myArray = Array("cells","range","function","end","call","run ")

For each cell in selection
For i = 0 to ubound(array())
If cell = array(i) then
msgbox "One of your cells is using a reserved
word!",vbcritical
End if
Next i
Next cell

End Sub


This is air code, I did not test it. Just add the reserved words to
the Array(), I only added the ones I could think of off the top.


HTH,
JP


Yes, but this is only one check if a cell contents is a reserved word. I
must check if it follows VB naming rules.
Maybe my English is so poor, but this is not what I want.
Once again
I have some cells in worksheet, and I want to create a module with some
macros named like these cells contents.
So, for example I have in column data like this:
AAAA
bbbb
12a
aaa and bbb
cccc

Now I must to create 5 macros with the names determined by cells contents
so I must check if they follow visual basic naming rules. In this example
only first, second and last cell can be a valid function identifier. How
can I check this?