+ Reply to Thread
Results 1 to 9 of 9

macro to delete specified files in a folder

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    macro to delete specified files in a folder

    I have tried to write code to delete specified files in a folder C:\data analysis for eg BR1 Period 4 Sales Ledger.xls, BR2 period 5 Sales ledger.xls etc


    I have specified the folder in Col A , whether to include sub-folders in Col B and have shown part of the file name using a wildcard character in Col C


    I get a compile error : User defined type not specified


    Please Login or Register  to view this content.


    It would be appreciated if someone can test my code and amend it to suit my needs
    Attached Files Attached Files
    Last edited by Howardc1001; 12-05-2018 at 10:56 AM.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: macro to delete specified files in a folder

    From Tools >> References >> Check the option 'Microsoft scripting runtime'
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    Re: macro to delete specified files in a folder

    thanks for the help. I have done tht and macro runs but not files are deleted in the folder for eg BR1 period 4 Sales data.xls, BR1 period 5 Sales data.xls etc


    It would be appreciated if you could amend my code so that it deletes the files in col C containing a wildcard character

  4. #4
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,260

    Re: macro to delete specified files in a folder

    coba ini
    Please Login or Register  to view this content.
    "ThankyouFor Attention * And Your Help!!"

  5. #5
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    Re: macro to delete specified files in a folder

    Thanks for help. The files in the folder for period 4, Period 5, period 6, period 6 and period 8 which is in C2:C7 , which are csv files are not being deleted

    See one of the sample csv file as well as the file using your code


    Please test and amend code

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    Re: macro to delete specified files in a folder

    hi guys


    It would be appreciated if you could assist me in amending the code as the text in Col C containing part o the file name, is not being deleted

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: macro to delete specified files in a folder

    Remove the wildcard characters in Column C.
    Then for starters.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    Re: macro to delete specified files in a folder

    thanks for the help. Your code works perfectly

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: macro to delete specified files in a folder

    Glad to assist and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Move and Delete the same Folder & Files more than once to a different folder (3 Stages)
    By lauriejerome in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2017, 12:19 AM
  2. [SOLVED] Delete folder and subfolder OKB Files
    By laxmanann in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2014, 02:05 PM
  3. Replies: 1
    Last Post: 03-12-2013, 04:45 AM
  4. Macro to delete csv files in downloads folder
    By prontrad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2009, 06:48 AM
  5. Delete .csv files in a folder
    By John in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2006, 02:10 PM
  6. Delete files within a folder
    By tarzan538 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2006, 09:25 PM
  7. [SOLVED] Delete All Files in a folder
    By Michael Smith in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2005, 01:05 PM

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