Sunday, July 20, 2008

Clean Temp (.tmp) and Word Backup files (.wbk) using Word VBA

Delete Temp (.tmp) and Word Backup files (.wbk) using Word VBA

Temp and Backup files add unnecessary space on disk. It is good to delete them after you are sure of the original file. The following VBA function deletes/clears the temp and backup files from a specified folder. This function cannot be used in Word 2007 as Application.Filesearch is not supported

Function DeleteBackupsandTempFiles(ByVal Deletepath As String)

Dim fs1 As Object

fs1 = CreateObject("scripting.filesystemobject")

file_path = Deletepath

'--- Deletes all temp files in the particular folder

With Application.FileSearch

.LookIn = file_path

.filename = ".tmp"

.SearchSubFolders = False


If .FoundFiles.Count > 0 Then

For k1 = 1 To .FoundFiles.Count

On Error GoTo DeleteFileError


Next k1

End If

End With

Exit Function


If Err.Number = 70 Then


Resume Next



Resume Next

End If

End Function

To kill normal temp files please refer To get the location of Temporary folder please us

Application.Filesearch is not supported in 2007 (Excel/Word etc).

Be cautious while deleting Backup files and Temp files, Word creates these files when the document is Open for editing. Make sure you run this procedure in folders where you have completed work

No comments:

Post a Comment

Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.