PDA

View Full Version : Interacting the Search Dialogue Box



Mis_Sailesh
04-02-2010, 11:24 AM
Hi
Any one can help me, how to interact with Search Dialogue box of Window in VBA (Excel) coding?

I am able to display it from the coding and also can set the default folder, but I am looking to set the "Text to be searched" through code, or if possible just using the "Search Dialogue" box without its User Interface(i.e. in hidden way)....

:help

Mis_Sailesh
04-02-2010, 09:10 PM
Is there any one who can help me out of this???

Need this urgently....

GTO
04-03-2010, 12:06 PM
Greetings,

I am unclear as to what you are looking to do. Could you post a small example workbook showing what you have so far? .xls format would be preferable, as some of us still have older versions.

mikerickson
04-03-2010, 12:52 PM
Would the .Find method of a Range object do what you want?

Mis_Sailesh
04-03-2010, 08:28 PM
Thanks for the reply, Please find attached the workbook (.xls), kindly change the path of folder in cell "B4" of sheet "Sailesh Main" and then click on the button.

It brings the "Search Dialogue Box" and then the user has to enter "Text to be searched" and clicks "Search" of the dialogue box and finally window returns all the files containing the "Text to be Searched" in the Folder and sub folders in the standard search box.

However I don't want to show "Search Dialogue Box", only want to use its functionality in the VBA code.

My Scenario is to find a "Text/String" in all the files in the folder and in sub folders in the folder (number of files is approximately 3000), so using .find will be very slow, hence I am looking to use API for this.

Please let me know if I missed something ....
:help

mdmackillop
04-04-2010, 03:00 AM
If you are not using 2007 try filesearch

Sub dosearch()
With Application.FileSearch
.NewSearch
.LookIn = "C:\AAA" '<==== Change to suit
.TextOrProperty = InputBox("Enter search string")
.SearchSubFolders = True
.Filename = "*.xls"
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1) = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

Mis_Sailesh
04-04-2010, 03:14 AM
Thanks for replying,
However I am using 2007, with windows xp and vista, planning to upgrad to office 2010.

Kindly revert what I can use in this scenario...

:help

GTO
04-04-2010, 08:42 AM
I am afraid that I do not see a wb attached. Use the <Go Advanced> button below the Quick Reply box. Then scroll down a bit in the new window and use the <Manage Attachments> button. Fairly self-explanatory thereafter.

Mark

Mis_Sailesh
04-04-2010, 10:58 PM
Thanks for reply ...,I am not sure why the manage attachment option is not working, please see the codes below:-Option Explicit'API declaration for the windows &quot;Search Results&quot; dialogPrivate Declare Function ShellSearch& Lib &quot;shell32.dll&quot; _ Alias &quot;ShellExecuteA&quot; (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 = 1Sub ShowWindowsSearchDialog_API()' Specified drive to Search Dim szSDrive As String Dim i As Integer szSDrive = Sheets(&quot;Sailesh Main&quot;).Cells(4, 2).Value ShellSearch 0, &quot;find&quot;, szSDrive, &quot;&quot;, &quot;&quot;, SW_SHOWNORMALEnd SubThis macro is then assigned to a button, in sheet &quot;Sailesh Main&quot; and default folder is picked using &quot;Sheets(&quot;Sailesh Main&quot;).Cells(4, 2).Value&quot;.Please see if this serves the purpose...

Mis_Sailesh
04-06-2010, 04:03 AM
3214

Please find the attachement