Gustav Brock
Gustav at cactus.dk
Sat Jun 17 03:49:12 CDT 2006
Hi Bob Stuart is right. However, / isn't the only forbidden character. We use this function to clean user typed file names by replacing such chars with a dash: Function TrimFileName( _ ByVal strFileName As String) _ As String ' Replaces characters in strFileName that are ' not allowed by Windows as a file name. ' Truncates length of strFileName to clngFileNameLen. ' ' 2000-12-07. Cactus Data ApS, CPH. ' 2002-05-22. Replaced string concatenating with Mid(). ' No special error handling. On Error Resume Next ' String containing all not allowed characters. Const cstrInValidChars As String = "\/:*?""<>|" ' Replace character for not allowed characters. Const cstrReplaceChar As String * 1 = "-" ' Maximum length of a file name. Const clngFileNameLen As Long = 255 Dim lngLen As Long Dim lngPos As Long Dim strChar As String Dim strTrim As String ' Strip leading and trailing spaces. strTrim = Left(Trim(strFileName), clngFileNameLen) lngLen = Len(strTrim) For lngPos = 1 To lngLen Step 1 strChar = Mid(strTrim, lngPos, 1) If InStr(cstrInValidChars, strChar) > 0 Then Mid(strTrim, lngPos) = cstrReplaceChar End If Next TrimFileName = strTrim End Function /gustav >>> bheygood at abestsystems.com 17-06-2006 01:00 >>> Hello to the list, I am having a failure when running the line of code below: appExcel.ActiveWorkbook.SaveAs FileName:=strNewFileName This works well until I assign a value with a / to the variable - strNewFileName When I remove the / all is well. What's the best solution if my client insists on keeping the /s in the resulting file name? TIA Bob Heygood