When working with or fixing Access databases and Excel spreadsheets created by users at my company, I often have to use their strings from the table or spreadsheet to save the resultant fixed file. The problem is that the strings they use often contain illegal file-name characters. This function strips away the illegal characters and replaces them with an underscore character. To use the character, call the function, passing the string you want checked and stripped:
Public Function fConvert(ByVal sStr As String) As String Dim i As Integer Dim sBadChar As String ' List all illegal/unwanted characters sBadChar = "/?|*:'" ' Loop through all the characters of the string ' checking whether each is an illegal character For i = 1 To Len(sStr) If InStr(sBadChar, Mid(sStr, i, 1)) Then Mid(sStr, i, 1) = "_" End If Next I fConvert = sStrEnd Function