is it possible to start the windows search program running and to tell it to search a directory (eg c drive) for a word from a macro called from excel?
Cheers
Gibbo
is it possible to start the windows search program running and to tell it to search a directory (eg c drive) for a word from a macro called from excel?
Cheers
Gibbo
The word you want to search for is in the VBA code?
If your wanting to start the Windows Search Dialog:
Standard Module:
Option Explicit 'API declaration for the windows "Search" dialog Private Declare Function ShellSearch& Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) Private Const SW_SHOWNORMAL = 1 Sub ShowWindowsSearchDialog_API() ' Display the Search Dialog Const sSDrive As String = "C:\" ShellSearch 0, "find", sSDrive, "", "", SW_SHOWNORMAL End Sub
Justin Labenne
I was thinking about a vba routine where i could specify a word in an input box then it would use the windows search facility to search all files (And sub files ) in a directory for that word
Hmm.. okay, but how do you want it returned to you?
Do you want a list of all the file names that the word was found in?
Are we looking at all file types, or just Excel files?
Justin Labenne
sorry, posted before i saw the post above, thats what im trying to do but i need to be able to put a word in and start the search, any ideas?
Well, if you already know the word and the criteria, using the Windows dialog is really irrelevant because you know waht you need, so here is a bit using FileSearch: Look it up in help for more info but it should get you started:
Sub FindTextString() Dim i As Integer Const szSearchWord As String = "Hello" With Application.FileSearch .LookIn = "c:\Work" .FileType = msoFileTypeAllFiles .SearchSubFolders = False .TextOrProperty = szSearchWord .Execute For i = 1 To .FoundFiles.Count MsgBox .FoundFiles(i) Next i End With End Sub
Justin Labenne
solved again thanks
Gibbo