monitor filesearch

taj

New Member
Joined
Sep 24, 2004
Messages
5
I am using FileSearch.SearchSubFolders and finding it takes a significant amount of time (~10 sec). Is there any way, while the FileSearch is working to display to the user some indication that things are not frozen. I'm hoping for something more "in your face" than the status bar text. I have an animated non-modal userform, but I find that it doesn't redraw while the filesearch is proceeding - it just shows blank white.

Thanks for any suggestions.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I use this, it automatically calculates the progress bar:

Private Sub UserForm_Activate()
'User Form Code Module.
'You must make a userform with a progressBar on it!
'Note the progressbar is on "More Controls" [Right Click ToolBox].
Dim MyStart, MyDelay, MyFinish, CompletePct, MyCodeEndTest

'Sample code Defines.
Dim n As Integer
Dim MyCell As String
'Sample code Defines.

On Error GoTo MyEnd
MyCodeEndTest = False
n = 0
'Note: Timer in 100ths of a second.
MyStart = Timer
MyDelay = 5
MyFinish = MyStart + MyDelay
Do Until Timer > MyFinish

'This is part of the sample test code, you may not need this!
For a = 1 To 150000
'This is part of the sample test code, you may not need this!

CompletePct = (MyFinish - Timer) / MyDelay
Application.ScreenUpdating = True
UserForm1.ProgressBar1.Value = 100 - (CompletePct * 100)

'Your code to run with a "ProgressBar" go's here!
'Delete code between: This is sample...

'This is sample test code only!
Application.ScreenUpdating = False
n = n + 1
MyCell = "A" & n
Sheets("Sheet1").Select
Sheets("Sheet1").Range(MyCell).Select
Application.ScreenUpdating = True
Selection.Value = "Test"
Application.ScreenUpdating = False
Next a
'This is sample test code only!

'End your code with a "Done" test: MyCodeEndTest = True
MyCodeEndTest = True
If MyCodeEndTest = True Then GoTo MyEnd
Loop
MyEnd:
Unload UserForm1

'This is optional code!
Application.ScreenUpdating = True
MsgBox "Done!"
Sheets("Sheet1").Range("A:A").Value = ""
Sheets("Sheet1").Range("A1").Select
'This is optional code!

End Sub


Sub myXStart()
'Standard Module code like: Module1.
'This starts the ProgressBar user form that contains your code!

UserForm1.Show

End Sub
 
Upvote 0
This puts up a cloud message!

Sub PleaseWait()
'Standard Module code!

With ActiveSheet.Shapes.AddShape(msoShapeCloudCallout, 200, 150, 150, 100)
.Name = "Wait a bit"
.TextFrame.Characters.Text = "Please Wait..." & Chr(10) & "I am working..." & Chr(10) & Chr(10) & "NOW!"
.TextFrame.HorizontalAlignment = xlHAlignCenter
.TextFrame.VerticalAlignment = xlVAlignCenter
End With
Application.OnTime Now + 10 / 86400, "WaitOver"
End Sub

Sub WaitOver()
On Error GoTo myEnd
ActiveSheet.Shapes("Wait a bit").Delete
myEnd:
End Sub
 
Upvote 0
Joe, Thanks for the code - I wasn't even aware of the right click additional tools, and premade progress bar. Unfortunately, my code to run in place of your sample test code is:

Set fs = Application.FileSearch
With fs
.LookIn = "C:"
.SearchSubFolders = True
.Filename = "some_buried_file"
If .Execute > 0 Then
MsgBox "Found some_buried_file."
Else
MsgBox "Can not find some_buried_file."
End If
End With

This doesn't seem to kick out for redrawing the progress bar. That's why I tried to have a non-modal userform running and redrawing concurrently as an indication of activity - but with no luck. Is this simply unworkable?
 
Upvote 0
This works I added your code to it and tested it!

Sub PleaseWait()
'Standard Module code!

With ActiveSheet.Shapes.AddShape(msoShapeCloudCallout, 200, 150, 150, 100)
.Name = "Wait a bit"
.TextFrame.Characters.Text = "Please Wait..." & Chr(10) & "I am working..." & Chr(10) & Chr(10) & "NOW!"
.TextFrame.HorizontalAlignment = xlHAlignCenter
.TextFrame.VerticalAlignment = xlVAlignCenter
End With

'Your Code starts!
Set fs = Application.FileSearch
With fs
.LookIn = "C:"
.SearchSubFolders = True
.Filename = "some_buried_file"
If .Execute > 0 Then
MsgBox "Found some_buried_file."
Else
MsgBox "Can not find some_buried_file."
End If
End With
'Your Code Ends!

On Error GoTo myEnd
ActiveSheet.Shapes("Wait a bit").Delete
myEnd:

'Application.OnTime Now + 10 / 86400, "WaitOver"
End Sub
 
Upvote 0
Thanks again. I like the cloud message. (I was too slow with my first reply - it was in response to the progress bar code - which I couldn't get to work with the filesearch) The cloud message I think address the issue.
 
Upvote 0
I tested the progress bar with your code.

The file search function is non-interuptable so the progress bar will not work, but if you search one file at a time then update the bar it may work?

You will need to index and use "item" to do it. I am not having any luck with this method though at the moment?
 
Upvote 0

Forum statistics

Threads
1,225,247
Messages
6,183,834
Members
453,190
Latest member
Makri93

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top