Private Declare Function FindExecutable Lib "shell32.dll" Alias _ "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, _ ByVal sResult As String) As Long
Private Const MAX_PATH = 260 Private Const ERROR_FILE_NO_ASSOCIATION = 31& Private Const ERROR_FILE_NOT_FOUND = 2& Private Const ERROR_PATH_NOT_FOUND = 3& Private Const ERROR_FILE_SUCCESS = 32&
Public Function GetExecutableFile(ByVal FileName As String) As String Dim sPath As String, sFile As String Dim lPos As Long Dim sResult As String
lPos = InStrRev(FileName, "\") If lPos = 0 Then Exit Function sPath = Left$(FileName, lPos) sFile = Mid$(FileName, lPos + 1) sResult = Space(MAX_PATH) Select Case FindExecutable(sFile, sPath, sResult) Case ERROR_FILE_NOT_FOUND Err.Raise 53 Case ERROR_PATH_NOT_FOUND Err.Raise 76 Case ERROR_FILE_NO_ASSOCIATION Case Is >= ERROR_FILE_SUCCESS GetExecutableFile = Left$(sResult, InStr(sResult & vbNullChar, _ vbNullChar) - 1) End Select End Function |