FILESEARCH OBJECT

  • Thread starter Thread starter jason
  • Start date Start date
J

jason

HOW COME IF I RUN THE BELOW AND IF THE .FoundFiles.Count DOES ACTUALLY
EQUAL 0 THEN IT WILL SAVECOPYAS OF THE FILE IN THE APPROPRIATE PLACE.
THE TROUBLE IS THAT IF I RUN THE CODE AGAIN IT STILL HAS THE
..FoundFiles.Count AS 0 !! THE ONLY WAY IT WILL RECOGNISE THE NEWLY
SAVED FILE IS IF I LOG OFF THE SERVER AND RE-RUN THE CODE !

ANY ONE GOT ANY IDEAS HOW I CAN MODIFY THE CODE TO AVOID THE ABOVE?

ANY HELK GREATLY APPRECIATED.

JASON

Function SaveThisWorkBook()

Dim fs As FileSearch
Set fs = Application.FileSearch
With fs
.LookIn = "I:\Finance\PIMS\Archived Log"
.Filename = "Log " & Format(Now, "dd mmm yyyy") & ".xls"
If .FoundFiles.Count = 0 Then
ThisWorkbook.SaveCopyAs "I:\Finance\PIMS\Archived
_ Log\Log " & Format(Now, "dd mmm _ yyyy") & ".xls"
End If
End With
Set fs = Nothing

End Function
 
Jason

This shouldn't be an issue but try using the Execute method explicitly and
then set the AlwaysAccurate parameter to True. This will ensure the index
of the folder is updated before the filesearch, like (untested). You might
also try NewSearch each time to invoke 'new' parameters.

With fs
.LookIn = "I:\Finance\PIMS\Archived Log"
.Filename = "Log " & Format(Now, "dd mmm yyyy") & ".xls"
If .Execute(, , True) = 0 Then
ThisWorkbook.SaveCopyAs "I:\Finance\PIMS\Archived
_ Log\Log " & Format(Now, "dd mmm _ yyyy") & ".xls"
End If
End With

PS: Upper case posts are considered shouting and rude in text only NGs

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top