Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default how do i run an external file

I need to run a file that has a non-common extension from an
excel Command Button.
Mypath/myfile.BIN
Shell does not work for this. Can anyone help.
The file will load when double-clicked from windows. It automatically
loads the program required to open the file and runs it.
Is there a command or another syntax that can be used to
open this type of file through a command Button.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default how do i run an external file

Here's a post I saved from Chip Pearson:

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

KJ MAN wrote:

I need to run a file that has a non-common extension from an
excel Command Button.
Mypath/myfile.BIN
Shell does not work for this. Can anyone help.
The file will load when double-clicked from windows. It automatically
loads the program required to open the file and runs it.
Is there a command or another syntax that can be used to
open this type of file through a command Button.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open external data (varying file names) and closing file once data is retrieved Corrie Excel Programming 2 December 31st 06 09:56 PM
Sumif to external file harriettbird Excel Discussion (Misc queries) 1 September 22nd 06 07:37 PM
How do I reference external data from a file, file name found in . Clux Excel Discussion (Misc queries) 1 February 10th 05 10:52 PM
Opening an external file lilnuba Excel Programming 1 August 18th 04 04:56 PM
Get External Data, Import Text File, File name problem Scott Riddle Excel Programming 1 July 11th 03 05:40 PM


All times are GMT +1. The time now is 09:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"