PDA

View Full Version : Solved: Don't allow Special Characters



Djblois
12-26-2006, 01:19 PM
I am using a dialog box to ask a user to name a tab in their workbook and I know certain special characters won't work in tabs.

1) Does anyone know which special characters are not allowed for tab names?
2) Does anyone know how to not allow the user to enter those characters in the dialog box. Preferably, I want it to create a dialog box saying "You can no use " and that what ever characters are not permitted, when the user hits enter

Thank you

stanl
12-26-2006, 02:18 PM
1) Does anyone know which special characters are not allowed for tab names?


: \ / ? * [ or ] are not allowed. Stan

Zack Barresse
12-26-2006, 02:22 PM
Hi Djblois,

What kind of dialog box are we talking about? An InputBox? A UserForm TextBox? Please be more specific. If it is code, please post the code in question.

And the characters not allowed in a sheet name are:


'
*
/
:
?
[
\
]

HTH

Djblois
12-26-2006, 02:23 PM
Thank you Stan,

Now if someone can please help me with my 2nd request, it would be great.

Zack Barresse
12-26-2006, 02:26 PM
More information is needed. Read post #3 above.

Djblois
12-26-2006, 05:16 PM
Sorry firefytr,

I must have typed my post while you were typing yours. However, it is a userform textbox.

Ivan F Moala
12-26-2006, 07:20 PM
The are a number of ways to do this here is but 1.



Private Function fnKeyPressFilter(ByVal KeyAscii As Integer, _
AcceptCharacters As String) As Integer

'// Accept the Delete Key to enable Editing!
If KeyAscii = 8 Then Exit Function

'// Is this Key in the list of characters to deny
If InStr(1, AcceptCharacters, Chr$(KeyAscii)) > 0 Then
fnKeyPressFilter = 0
Beep
Else
'// Must be OK
fnKeyPressFilter = KeyAscii
End If

End Function

'// your TextBox
Private Sub Databox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'// ALSO Set your TextBox MaxLength limit to 32!
If fnKeyPressFilter(KeyAscii, "/\'[*") = 0 Then KeyAscii = 0
End Sub



Can anyone confirm that ] is an illegal character for sheet names ??
Also History is a Reserved name for a worksheet name.

Ivan F Moala
12-26-2006, 07:43 PM
Did a test and got these illegal characters
'
*
/
:
?
[
\


where as MS popup error says
: \ / ? * [ or ]

Brandtrock
12-26-2006, 08:38 PM
I can't use ] in addition to your list Ivan.

An apostrophe ( ' ) will work so long as it isn't the first character though.

stanl
12-27-2006, 06:46 AM
just .02, but in addition to special chars you might also want to check if the sheetname already exists. Stan

Djblois
12-27-2006, 07:39 AM
Stan,

Thank you for the advice. However, I already check that.

Djblois
12-28-2006, 07:32 AM
Where do I put the Function code in a Module or Class Module?

Bob Phillips
12-28-2006, 07:37 AM
Put it in the userform code module.

Djblois
12-28-2006, 07:42 AM
Thank you again Xld that worked.

Bob Phillips
12-28-2006, 08:22 AM
Don't thank me, I just told you where to stick it :rofl: