Consulting

Results 1 to 8 of 8

Thread: Windows search

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Windows search

    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

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    The word you want to search for is in the VBA code?

  3. #3
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    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

  4. #4
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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

  5. #5
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    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

  6. #6
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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?

  7. #7
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    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

  8. #8
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    solved again thanks

    Gibbo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •