Lookin Property.

S

Simon

How can i reset this property, with out closing down and
reopening Excel.

Trying to do many file searches in different Dir within
one Marco.

the property .newsearch only resets the file name to
search for.

Any help?

THanks Simon
 
T

Tom Ogilvy

Just set the property for each search

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
 
S

Simon

Thank you Tom
but i have create the following

If loop = 1 then
f_dir = "C:\"
else
f_dir = "D:\"
endif

With Application.FileSearch
.NewSearch
.LookIn = f_dir

and call this a couple of times. The Lookin value does not
change

Regards

Simon
 
B

Bob Phillips

Not a good idea to use the word loop as a variable, it is VBA reserved
word.

And where is the loop that increments that variable?

Change it and try again. Why did you not get a compile error?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
S

Simon

i did not get an error, i have inserted the code.

Any ideas.?

Thanking you in advance.
Simon

sub srj_a()

S_loop = 1
Do While S_loop <> 3
If s_loop = 1 then
f_dir = "C:\"
f_name = "S*.TXT
else
f_dir = "D:\"
f_name = g*.txt
endif
Call ReCalc_files(f_dir, f_name)
loop
end sub

sub Recalc_files(f_dir, f_name)

With Application.FileSearch
.NewSearch
.LookIn = f_dir
.FileName = f_name
.....ETC

end sub

******************************************
 
B

Bob Phillips

You are not incrementing the loop counter, and the second f_name is not a
string

Sub srj_a()
Dim s_loop, f_dir, f_name

s_loop = 1
Do While s_loop <> 3
If s_loop = 1 Then
f_dir = "C:\"
f_name = "S*.TXT"
Else
f_dir = "D:\"
f_name = "g*.txt"
End If
Call Recalc_files(f_dir, f_name)
s_loop = s_loop + 1
Loop
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
G

Guest

after my inital exciment met it still is NOT working?
The complete code.

Regards Simon

Sub Macro1()

Dim s_loop, f_dir, f_name

s_loop = 1
Do While s_loop <> 3
If s_loop = 1 Then
f_dir = "C:\Simon"
f_name = "S*.TXT"
Else
f_dir = "D:\Simon"
f_name = "g*.txt"
End If
Call Recalc_files(f_dir, f_name)
s_loop = s_loop + 1
Loop
End Sub

Sub Recalc_files(f_dir, f_name)
Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = f_dir
.FileName = f_name
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
 
B

Bob Phillips

What doesn't work?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top