pctechguide.com

  • Home
  • Guides
  • Tutorials
  • Articles
  • Reviews
  • Glossary
  • Contact

VBA Macro to Delete All TMP Files in Multiple Folders

I have done a lot of work with Photoshop, where I end up having a ton of annoying TMP files after running a large batch action. This can take up unnecessary storage space and make it harder to sort through useful files.

Finding and deleting TMP files can be a huge pain. You can go to folder and search for all files by putting .TMP in the search box. However, there are reasons this may not work:

  • You may have a very large set of files and the computer may not be able to search through all of them.
  • You may have files in numerous folders that don’t even necessarily have the same parent folder.
  • It may accidentally identify files that are not TMP files that have the letters TMP in the file name.

This means that it can be better to use a VBA macro. This macro will go through all of the folder paths shown in column A and delete every TMP file in them.

Sub DeleteTmpFiles()
Dim FolderPath As String
Dim FileName As String
Dim FileSystem As Object
Dim objFolder As Object
Dim objFile As Object
Dim LastRow As Long
Dim i As Long

' Create an instance of the FileSystemObject
Set FileSystem = CreateObject("Scripting.FileSystemObject")

' Find the last row with data in column A
LastRow = Cells(Rows.Count, 1).End(xlUp).Row

' Loop through each cell in column A
For i = 1 To LastRow
    ' Get the folder path from column A
    FolderPath = Cells(i, 1).Value

    ' Check if the folder path is valid
    If FileSystem.FolderExists(FolderPath) Then
        ' Set objFolder to the folder path
        Set objFolder = FileSystem.GetFolder(FolderPath)

        ' Loop through each file in the folder
        For Each objFile In objFolder.Files
            ' Check if the file is a TMP file
            If LCase(Right(objFile.Name, 4)) = ".tmp" Then
                ' Delete the TMP file
                objFile.Delete
            End If
        Next objFile
    Else
        ' Display a message if the folder path is invalid
        MsgBox "Folder does not exist: " & FolderPath, vbExclamation
    End If
Next i

' Clean up objects
Set FileSystem = Nothing
Set objFolder = Nothing
Set objFile = Nothing

' Display a message when the task is completed
MsgBox "TMP files deleted successfully!", vbInformation

End Sub

Temporary files can take a lot of space over time. This can cause your computer to run more slowly if you are not careful. Therefore, it is a good idea to get rid of TMP files that you don’t need any more.

This macro will get rid of them automatically for you. You probably don’t need temporary files much after you have finished a project, so this can be a great way to have more free memory.

Filed Under: Articles

Latest Articles

Symantec Internet Security Review

[starreviewmulti id=7 tpl=20] PROS: Norton Internet Security is one of the most trusted brand out there for protecting computers. Real time updates. Protects against all forms of attacks. CONS: As with every Internet Security Suite it can bog down your computer. OVERVIEW: Overall this … [Read More...]

How to hide the likes count of your Instagram posts

Instagram is a very popular social networking site. Many people like using Instagram, because of its very open nature. However, this is not always something that people enjoy. You might want to have a little more privacy. You may even want to hide some of your account details, such as the number … [Read More...]

How to Remove Unlimited Defender

Easiest Removal Option: Remote Repair: Paying an expert to remove this threat is always the easiest option. It's also the most expensive. PCTechGuide.com has reviewed several remote computer repair companies and we recommend http://www.pcninja.com This is a small computer repair company (Two … [Read More...]

20 Cool Creative Commons Photographs About the Future of AI

AI technology is starting to have a huge impact on our lives. The market value for AI is estimated to have been worth $279.22 billion in 2024 and it … [Read More...]

13 Impressive Stats on the Future of AI

AI technology is starting to become much more important in our everyday lives. Many businesses are using it as well. While he has created a lot of … [Read More...]

Graphic Designers on Reddit Share their Views of AI

There are clearly a lot of positive things about AI. However, it is not a good thing for everyone. One of the things that many people are worried … [Read More...]

Redditors Talk About the Impact of AI on Freelance Writers

AI technology has had a huge impact on our lives. A 2023 survey by Pew Research found that 56% of people use AI at least once a day or once a week. … [Read More...]

11 Most Popular Books on Perl Programming

Perl is not the most popular programming language. It has only one million users, compared to 12 million that use Python. However, it has a lot of … [Read More...]

10 Exceptional Books on ChatGPT that Will Blow Your Mind

ChatGPT is a powerful new AI tool that is taking the world by storm. You are going to find a lot of amazing books that will teach you how to make the … [Read More...]

Guides

  • Computer Communications
  • Mobile Computing
  • PC Components
  • PC Data Storage
  • PC Input-Output
  • PC Multimedia
  • Processors (CPUs)

Recent Posts

1999 Site Updates

Date Details of updates 22Dec '99 New millennium changes: The site is honoured to become an affiliate of the Maximum PC Network, operated by … [Read More...]

2006 Update History of the PC Technology Guide

Date Details of site updates in 2006 28Nov '06 A & E content updated: New article on Number Systems added, covering … [Read More...]

ADSL Sharing

Sharing your broadband Internet across multiple computers is simply a matter of connecting the other PCs to the local network and setting up their … [Read More...]

[footer_backtotop]

Copyright © 2025 About | Privacy | Contact Information | Wrtie For Us | Disclaimer | Copyright License | Authors