Quote:
> Is there any easy way to find the path to an application in VB 5.0.
> What I want to do is to is to find out where e.g. Excel is installed and
> thereafter start Excel with the shell() function.
You can pass the following function any "excel" file, such as
"workfile.xls" and it will return the full name of the "associated"
program. Assuming that EXCEL is associated with .xls files, this may do
the trick.
Declare Function FindExecutable& Lib "shell32.dll" Alias "FindExecutableA"
(ByVal lpFile$, ByVal lpDir$, ByVal lpResult$)
Public Function GetAssociatedProgram$(ByRef LookFor$)
Dim Result$
Dim x&
Dim API_Result&
Dim FileName$
Dim PathName$
Dim Temp$
Result$ = Space$(3000)
x& = StringFindLast&(LookFor$, "\")
If x& > 0 Then
PathName$ = Left$(LookFor$, x&)
FileName$ = Mid$(LookFor$, x& + 1)
Else
x& = StringFindLast&(LookFor$, ":")
If x& > 0 Then
PathName$ = Left$(LookFor$, x&)
End If
FileName$ = Mid$(LookFor$, x& + 1)
End If
API_Result& = FindExecutable&(FileName$, PathName$, Result$)
If API_Result& > 32 Then
API_Result& = InStr(Result$ & Chr$(0), Chr$(0))
GetAssociatedProgram$ = Trim$(Left$(Result$, API_Result& - 1))
Else
GetAssociatedProgram$ = ""
End If
End Function
Public Function StringFindLast&(ByRef InString$, ByRef FindPart$, Optional
StartPos As Long = 1)
' Finds the last occurence of a substring.
Dim FoundPos&
FoundPos& = InStr(StartPos, InString$, FindPart$)
If FoundPos& > 0 Then
StringFindLast& = lngMax&(FoundPos&, StringFindLast&(InString$,
FindPart$, FoundPos& + 1))
Else
StringFindLast& = 0
End If
End Function
Public Function lngMax&(ByRef x&, ByRef y&)
If x& > y& Then lngMax& = x& Else lngMax& = y&
End Function