ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   FILESEARCH OBJECT (https://www.excelbanter.com/excel-programming/319732-filesearch-object.html)

jason

FILESEARCH OBJECT
 
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

Nick Hodge

FILESEARCH OBJECT
 
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
HIS


"jason" wrote in message
om...
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





All times are GMT +1. The time now is 02:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com