View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
A-DESIGN A-DESIGN is offline
external usenet poster
 
Posts: 40
Default Code To find and run an EXE file out side of the Excel

Thank Tom,

I am not sure about this but I think using the "Dir" command in "DOS" mode
plus " /S " switch and finally process the results would help, don't you
think so? Thanks,

Regards,
Afshin.


"Tom Ogilvy" wrote in message
...
I don't
know of any built in file searching function in VBA.


Use the filesearch object.

sStr1 = "excel.exe"
set fs = Application.FileSearch
With fs
.NewSearch
.FileName = sStr1
.LookIn = "C:\"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
fs.Execute

sStr2 = ""
For r = 1 To fs.FoundFiles.Count
if instr(len(fs.foundfiles(r))-(len(sStr1)-1),fs.FoundFiles(r), _
sStr1,vbTextCompare) then
sStr2 = fs.FoundFiles(r)
fr = r
exist for
end if
Next r
if sStr2 < "" then
msgbox fs.FoundFiles(fr) & " was found"
End If

It only searches one path and its subdirectories, so if you can narrow it
down to which drive it should work, or you can loop over all drives.

--
Regards,
Tom Ogilvy


"kkknie" wrote in message
...

To run it, just use the Shell command:

Shell("c:\winnt\notepad.exe")

To find it, you will have to have some clue where it might be. I don't
know of any built in file searching function in VBA. Someone may have
posted one, so do a search for it (or a google search for VBA file
search).

If it may be in a couple of places, you could use the DIR command to
see if it is the

s = Dir("c:\windows\notepad.exe")
if s < "" then Shell("c:\windows\notepad.exe")

s = Dir("c:\winnt\notepad.exe")
if s < "" then Shell("c:\windows\notepad.exe")

etc.

K


--
kkknie
------------------------------------------------------------------------
kkknie's Profile:

http://www.excelforum.com/member.php...fo&userid=7543
View this thread:

http://www.excelforum.com/showthread...hreadid=266619