+ Reply to Thread
Results 1 to 12 of 12

Code request to delete files from folder

  1. #1
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Code request to delete files from folder

    Hello friends,

    I have several files in an ‘OUTPUT’ folder with different extensions as ‘docx, docm, pdf, xlsx … ‘. I have to delete some files which have extension ‘docx, xls … ‘ as per my requirement.

    Please suggest me a code to delete the files in the folder as per my requirement.
    First I want to select which format extension to delete and after selecting the format I want to delete the file with that selected extension automatically.

    Any help will be highly appreciated.

    Thanking you in anticipation.
    Sincerely,

    mso3

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,876

    Re: Code request to delete files from folder

    Look at this link. Be sure to read it all the way to the end for alternatives.

    http://www.rondebruin.nl/win/s4/win004.htm
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code request to delete files from folder

    Hello mso3,

    This is simple to do. Here is a macro that will let you assign the file types you want to delete. If you have any questions, please ask.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Code request to delete files from folder

    Hello Leith Ross,

    Greetings from me!

    Excellent! Perfect solution.

    It's working fine but I want a little revision in it as:
    Now we have to type the file format extension in the code to delete the files; instead of it I want a dialog box to ask the format extension to delete. Because sometimes I don't want to delete the files of any particular format, for ex. now if I want to keep .xlsx extension files but the code deletes it because we have type it in the code. So to avoide this problem I need a dialog box to ask which file extension do you want to delete?

    Thank you.

  5. #5
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Code request to delete files from folder

    Hi Alan,

    Thank you for an informative site to learn a lot.

    I found it very useful.

    Thank you and have a nice day.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code request to delete files from folder

    Hello mso3,

    Do you want a dialog with check boxes? This would help prevent errors due to typing.

  7. #7
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Code request to delete files from folder

    Ok, no problem.

    Thank you.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code request to delete files from folder

    Hello mso3,

    The attached workbook has a UserForm, Standard VBA Module and a Class Module. All of these provide a user interface for selecting the folder and file types to be deleted.

    I know this is a lot more that what you asked for. Deleting files requires safeguards to prevent accidental deletion of files. A simple dialog box can not provide that protection.

    You can add more file types to the UserForm if needed. If you are unsure how to do this, let me know and I can guide through the process.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Code request to delete files from folder

    Hi Leith Ross,

    Greetings from me!

    Please insert a dialog box to our first program to ask which file format do you want to delete and problem will be solved.
    Sorry for trouble.

    Have a nice day.
    Last edited by mso3; 11-02-2015 at 09:54 PM.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code request to delete files from folder

    Hello mso3,

    Try this version and let me know if it needds any changes.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Code request to delete files from folder

    Hello Leith Ross,

    Excellent! Perfect solution. It's working fine as per my requirement.

    Thanks for taking extra trouble for me.

    Have a nice time.

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code request to delete files from folder

    Hello mso3,

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel VBA code for selecting a folder then search & open specified files in that folder
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2021, 03:09 AM
  2. [SOLVED] Help request to convert all the word files to PDF stored in a folder
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2016, 07:06 AM
  3. [SOLVED] VB Code to delete files from folder
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2015, 09:25 AM
  4. Code request to restrict user to edit/delete after -- days
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2015, 12:48 PM
  5. [SOLVED] VBA Code to Move Individual Files from 1 Folder to a new Folder
    By mike.lawrie448 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-21-2014, 07:05 AM
  6. Code request to delete numbers in column B automatically
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2014, 12:53 AM
  7. Excel Macro Code Request for List files and Move specified directory
    By ganeshinscribe in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-19-2012, 08:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1