Function ResolveExistingFile(strFileName, strErrorMessage) 'As String 'This function will return the full path and file name of a supplied file name 'strFileName = The supplied file name. May be a full path or just a bare name. 'strErrorMessage = This value will be modified to contain an error message if the function fails. Dim fs Dim wsh Dim strExistingFile Set wsh = CreateObject("WScript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") If Instr(strFileName, ":\") = 2 Then 'Full path supplied with input file If fs.FileExists(strFileName) Then 'Input file exists. Set the name. ResolveExistingFile = strFileName Exit Function Else 'Input file does not exist strErrorMessage = "File """ & strFileName & """ does not exist." ResolveExistingFile = "" Exit Function End If Else 'No path supplied with file. Try to make an intelligent guess. strExistingFile = "" 'Is it in the My Documents folder? If fs.FileExists(fs.BuildPath(wsh.SpecialFolders("MyDocuments"), strFileName)) Then If MsgBox("Use the file """ & fs.BuildPath(wsh.SpecialFolders("MyDocuments"), strFileName) & """?", vbYesNo, "File Name") = vbYes Then strExistingFile = fs.BuildPath(wsh.SpecialFolders("MyDocuments"), strFileName) End If End If 'Is it in the current directory? If ((strExistingFile = "") And (fs.FileExists(FileNameInCurDir(strFileName)))) Then If MsgBox("Use the file """ & FileNameInCurDir(strFileName) & """?", vbYesNo, "File Name") = vbYes Then strExistingFile = FileNameInCurDir(strFileName) End If End If 'Is it in the script directory? If ((strExistingFile = "") And (fs.FileExists(FileNameInThisDir(strFileName)))) Then If MsgBox("Use the file """ & FileNameInThisDir(strFileName) & """?", vbYesNo, "File Name") = vbYes Then strExistingFile = FileNameInThisDir(strFileName) End If End If If strExistingFile = "" Then strErrorMessage = "Unable to locate """ & strFileName & """ in the documents, current, or script directories." ResolveExistingFile = "" Exit Function Else ResolveExistingFile = strExistingFile Exit Function End If End If 'Should never get here ResolveExistingFile = "" strErrorMessage = "Unexpected coding error resolving existing file name. Oops." End Function