Skip to content
Rodrigo Celso de Lima Porto edited this page Jan 14, 2026 · 2 revisions

Checks if a given string can be used as a valid file name by checking for illegal characters.

Syntax

FileNameIsValid( _
    FileName As String _
) As Boolean

Parameters

  • FileName: The string to be validated as a file name

Return Value

Returns True if the file name is valid, False if it contains illegal characters or is empty.

Remarks

  • Checks for the following illegal characters: \ / : * ? < > | [ ] "
  • Returns False for empty strings
  • Case-sensitive validation
  • Does not check file name length restrictions
  • Does not validate against reserved Windows file names

Example

Dim isValid As Boolean

isValid = FileNameIsValid("my_file.txt")
Debug.Print isValid ' True

isValid = FileNameIsValid("file*.txt") 
Debug.Print isValid ' False

isValid = FileNameIsValid("folder/file.txt")
Debug.Print isValid  ' False

Credits

Clone this wiki locally