Andrew,
Here's something I dug up from one of my library files. It uses
FindExecutable to get the exe file that is associated with the extension of
the specified filename. (e.g., it gets Excel.exe for 'xls' extensions,
WinWord.exe for 'doc' extensions, etc). If different programs are specified
for different shell verbs (like OPEN and PRINT), it uses the exe specified
for the OPEN verb.
Public Declare Function FindExecutable Lib "shell32.dll" Alias
"FindExecutableA" ( _
ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long
Const MAX_PATH = 260&
Function ShellProgramFromFile(FName As String) As Boolean
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
' StartProgramFromFile
' This function finds the exe filename associated with the
' extension of FName and Shell's to that program, passing
' it FName.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
Dim ExeName As String
Dim Res As Long
Dim Pos As Long
If Trim(FName) = vbNullString Then
ShellProgramFromFile = False
Exit Function
End If
If Dir(FName, vbNormal + vbHidden + vbSystem) = vbNullString Then
ShellProgramFromFile = False
Exit Function
End If
ExeName = String$(MAX_PATH, vbNullChar)
Res = FindExecutable(FName, vbNullString, ExeName)
If Res < 32 Then
ShellProgramFromFile = False
Exit Function
End If
Pos = InStr(1, ExeName, vbNullChar)
If Pos Then
ExeName = Left(ExeName, Pos - 1)
End If
Shell Chr(34) & ExeName & Chr(34) & Chr(32) & Chr(34) & FName & Chr(34)
ShellProgramFromFile = True
End Function
Sub Test()
Dim FName As String
Dim Res As Boolean
FName = "C:\FW9.pdf" '<<<< CHANGE
Res = ShellProgramFromFile(FName:=FName)
End Sub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
"Andrew Hall NZ" wrote in message
...
To end my monologue, the solution given in the second post is now working
for
all file types. I am still unclear why Shell itself does not work, perhaps
it
is not compatible with XP, but in any case my problem is solved.
Andrew