View Full Version : [SOLVED] Windows search
gibbo1715
08-21-2005, 10:43 AM
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
Jacob Hilderbrand
08-21-2005, 11:13 AM
The word you want to search for is in the VBA code?
Justinlabenne
08-21-2005, 11:39 AM
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
gibbo1715
08-21-2005, 11:40 AM
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
Justinlabenne
08-21-2005, 11:51 AM
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?
gibbo1715
08-21-2005, 11:53 AM
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?
Justinlabenne
08-21-2005, 01:10 PM
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
gibbo1715
08-22-2005, 10:49 AM
solved again thanks
Gibbo
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.