Function CleanWorksheetName(ByRef strName As String) As String
Dim varBadChars As Variant
Dim varChar As Variant
varBadChars = Array(":", "/", "\", "?", "*", "[", "]")
For Each varChar In varBadChars
Select Case varChar
Case ":"
strName = Replace(strName, varChar, vbNullString)
Case "/"
strName = Replace(strName, varChar, "-")
Case "\"
strName = Replace(strName, varChar, "-")
Case "?"
strName = Replace(strName, varChar, vbNullString)
Case "*"
strName = Replace(strName, varChar, vbNullString)
Case "["
strName = Replace(strName, varChar, "(")
Case "]"
strName = Replace(strName, varChar, ")")
End Select
Next varChar
strName = Left(strName, 31)
CleanWorksheetName = strName
End Function
|