• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Calling the Find Files or Folders App

How do you call the Find File or Folders App from a command button?
0
UpAllNite
Asked:
UpAllNite
  • 4
1 Solution
 
swiltCommented:
Private Sub Command1_Click()
    Dim x As Variant
    Dim i As Integer
   
    x = Shell("Explorer", vbNormalFocus)
    If x <> 0 Then
        SendKeys "^f", True     'Ctrl f to invoke FindFiles from Explorer
        AppActivate "Exploring - C:\"
        SendKeys "%{F4}", True  'Alt F4 to close Explorer
        For i = 1 To 100
            DoEvents
        Next i
        AppActivate "Find: All Files"
    End If
End Sub

0
 
swiltCommented:
Did it not work or was it not what you wanted ?
0
 
UpAllNiteAuthor Commented:
It didn't work because, "Exploring - C:\" isn't always at startup, therefore AppActivate Errors occurr.  Secondly, I wanted to access the Find Files or Folders App without going through Explorer and sending SendKeys.

What I want is a call directly to the Find Files or Folders App.
0
 
swiltCommented:
Hope this works

Option Explicit

Private Declare Function ShellExecute 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) As Long

Private Sub Command1_Click()
    Dim sDir As String
    Dim nCmd As Long, nRet As Long
   
    sDir = "c:\"
    nCmd = 1
    nRet = ShellExecute(Me.hwnd, "Open", "temp.fnd", "", sDir, nCmd)
End Sub

Private Sub Form_Load()
    Dim fh As Integer
    Dim sFile As String, sTok As String
   
    sFile = "68,70,3,32,1,48,32,32,255,255,16,32,32,32,32,32,1,32,32,32,38,32,32,32,255,255,255,255,4,32,32,32,17,55,2,32,48,32,32,32,32,32,17,55,4,32,48,32,32,32,42,32,32,32,32,32,32,32,78,84,70,70,58,15,235,119,0"
   
    fh = FreeFile
    Open "c:\temp.fnd" For Binary As #fh
    sTok = sChopStr(sFile)
    While sTok <> ""
        Put #fh, , Chr$(Val(sTok))
        sTok = sChopStr(sFile)
    Wend
    Close #fh
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Kill "c:\temp.fnd"
End Sub

Private Function sChopStr(sInp As String) As String
    Dim p As Integer
    Dim sRet As String
   
    p = InStr(sInp, ",")
    If p > 0 Then
        sRet = Left$(sInp, p - 1)
        sInp = Mid$(sInp, p + 1)
    Else
        sRet = sInp
        sRet = ""
    End If
    sChopStr = sRet
End Function

0
 
swiltCommented:
Replace Form_Load with the following code and delete function sChopStr
It should still work but be a bit simpler

Private Sub Form_Load()
    Dim fh As Integer
     
    fh = FreeFile
    Open "c:\temp.fnd" For Binary As #fh
    Put #fh, , " "
    Close #fh
End Sub

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now