Macro to find file path of specific file.

M

MrKrich

Can anybody please tell me how to write the macro that
find the file path of file such as word.txt or
notepad.exe in the computer?
 
D

dz

Found this code in the VBA help index and then tweaked it
a bit for your needs. So, instead of MsgBox, create a
string variable and capture the path. However, it can be
quite slow if you don't give it at least a starting
directory (i.e., c:\winnt). Hope this helps.

DZ

With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.FileName = "notepad.exe"
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
.Execute
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top