Run Exe file
Hi Joel thank you for being so helpful
the code brings up the message box but does not tell you where it is
i was wondering if i could use this but replacing C:\Documents and
Settings\UserName with a wild card as the program will always be on the
Desktop but UserName will always be different
ID = Shell(Root & "C:\Documents and Settings\UserName\Desktop\Compiler.exe",
vbNormalFocus)
"Joel" wrote:
Here is a pair of macros that will recursively find a file on the C: drive.
You could also use FileSearch but it doesn't work in Excel 2007.
Public file_loc As String
Sub findfile()
'set MyFilename and strfold as required
'file to search for
Const MyFileName = "Compiler.exe"
'directory to start searching
strFolder = "c:\"
file_loc = ""
Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(strFolder)
Call GetWorksheetsSubFolder(strFolder + "\", MyFileName)
MsgBox ("File found in folder: " & file_loc)
End Sub
Sub GetWorksheetsSubFolder(strFolder, MyFileName)
Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(strFolder)
If folder.subfolders.Count 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetWorksheetsSubFolder(strFolder + sf.Name + "\", MyFileName)
If file_loc < "" Then Exit For
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
If file_loc = "" Then
For Each fl In folder.Files
If fl.Name = MyFileName Then
file_loc = folder.Name
End If
Next fl
End If
200 On Error GoTo 0
End Sub
"Arnie" wrote:
Hi all i am trying to use a portable bit of code to run "Compiler.exe" ie
could be anywhere on users PC so i need code to find the program and run it
any help would be appreciated
Code running from command Button
cheers Arnie
|