I want to use the following code to create a new folder and save the document in it with a filename taken from two cells on a sheet. But there is a chance to put characters like "/" and ":" in these cells which will cause an error since these characters cannot be used in filenames. Can I modify the code given below so that such characters will automatically be changed to an underscore instead of causing the error?
Function dirExists(dirAndPath) As Boolean Dim tempVar On Error Resume Next tempVar = Dir(dirAndPath & "\*.*", vbDirectory) If Err = 0 And tempVar <> "" Then dirExists = True End If On Error GoTo 0 End Function Sub SaveMe() Dim fname As String If Not dirExists("C:\Bill") Then MkDir "C:\Bill" fname = Sheets("Sheet1").Range("A1").Value & Sheets("Sheet1").Range("A2").Value & ".xls" ThisWorkbook.SaveAs Filename:="C:\Bill\" & fname End Sub