VB and VBA Users Source Code: Returning a valid filename (removing invalid characters)
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Returning a valid filename (removing invalid characters)
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, August 31, 2004
Hits:
5931
Category:
Files/Directories/IO
Article:
The code below returns a valid windows filename. 'Purpose : Removes invalid characters from a filename 'Inputs : sFileName The file name to clean the invalid characters from. ' [sReplaceInvalidWith] The text to replace any invalid characters with. 'Outputs : Returns a valid filename. 'Author : Andrew Baker 'Date : 25/03/2001 'Notes : Function FileNameValid(sFileName As String, Optional sReplaceInvalidWith As String = "") As String Const csInvalidChars As String = ":\/?*<>|""" Dim lThisChar As Long FileNameValid = sFileName 'Loop over each invalid character, removing any instances found For lThisChar = 1 To Len(csInvalidChars) FileNameValid = Replace$(FileNameValid, Mid(csInvalidChars, lThisChar, 1), sReplaceInvalidWith) Next End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder