I was using following code to clean the desktop from the files or to move files to another folder. Once the already exists in a folder it's receiving some random suffix.
Recently I installed Office 2007 and Office.FileSearch doesn't work for me. How can I change my code in order to code will start working.
Sub CleanDesktop() ' copy list of files from Desktop to folder according Dim tmpName As String Dim rng As Range Dim fsoFileSearch As Office.FileSearch Dim fsoFileSearch Dim varFile, FileName As Variant Dim FileCount As Integer Dim StartTime, EndTime As Date 'measure the time of a VB program that was run inside the VBA program Dim SourcePath, DestPath As String Dim oFs Dim oFile Dim oStream SourcePath = "C:\Documents and Settings\<username>\Desktop" & " \ " DestPath = "E:\Miscellaneous" & "\" On Error Resume Next ' if such file not found, ignore it If oFs.FileExists(DestPath) = True Then FileCount = 0 ' measure the time of a VB program that was run inside the VBA program StartTime = Timer With fsoFileSearch .NewSearch .LookIn = SourcePath .FileName = "*.*" .SearchSubFolders = True If .Execute() > 0 Then For Each varFile In .FoundFiles FileName = Split(varFile, "\")(4) If Dir$(DestPath & FileName) = "" Then FileCopy varFile, DestPath & FileName ' On Error Resume Next ' ignore any errors End If If Dir$(DestPath & FileName) <> "" Then ' adding random prefix for exist file FileCopy varFile, DestPath & Int((99999 - 10000 + 1) * Rnd + 10000) & "." & FileName ' On Error Resume Next ' ignore any errors End If ' file could be marked as readonly, you must first remove the readonly attribute from the file. SetAttr varFile, vbNormal Kill varFile FileCount = FileCount + 1 Next varFile End If End With ' measure the time of a VB program that was run inside the VBA program EndTime = Timer MsgBox ("Your files copied to " & DestPath & vbCrLf & "Copied " & FileCount & " files within " & _ Format(EndTime - StartTime, "0.0") & " sec") End Sub