file naming

tony.reynolds

Board Regular
Joined
Jul 8, 2010
Messages
97
I have a userform that the user can enter a new name for the workbook so the original is kept

i obviously need to limit the user data to certain characters so "\" is not allowed and also the original file name is not allowed

if the current excel file name is XYZ that is not allowed.... and

how can I limit users from entering these characters? \ / : * ? " < > |

The following code i have allows text only but obviously dosnt stop user entering a number following a letter and the above characters. Stillit it will show you what im trying to do.

Code:
Private Sub NewFileName_Change()
If IsNumeric(NewFileName.Value) Then
MsgBox "cannot use ' \ / : * ? " < > |' characters"
NewFileName.Value = ""
End If
End Sub

Anyons help would be appreciated
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
try something like this

Aint = InStr(1, NewFileName, Chr(XX))
If Aint > 0 Then
MsgBox "The character ' " & Chr(XX) & " ' is not allowed"
End If

Where XX=ASCII code for charater of insterest
 
Upvote 0
I would do something like this to evaluate the string

Code:
Function EvaluateString(strString As String) As String
   
    Dim i As Long
    For i = 1 To Len(strString)
        Select Case Asc(Mid(strString, i, 1))
            Case 65 To 90, 97 To 122: '(65-90UpperCaseAtoZ, 97-122LowerCaseatoz)
            'Case 32, 48 To 57 (32Space,48-57ZerotoNine)
            Case Else
                EvaluateString = Chr(Asc(Mid(strString, i, 1)))
                Exit For
        End Select
    Next
End Function
Private Sub NewFileName_Change()
    Dim result As String
    result = EvaluateString(NewFileName.Value)
    If result <> "" Then
        MsgBox "cannot use " & result & " characters"
        NewFileName.Value = ""
    End If
End Sub

thanks
tigs
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top