+ Reply to Thread
Results 1 to 6 of 6

Delete files from the listed file paths in the table

  1. #1
    Registered User
    Join Date
    02-08-2021
    Location
    us
    MS-Off Ver
    365
    Posts
    13

    Delete files from the listed file paths in the table

    Hi,

    I have one excel file with file name in one column and its folder path in other column. I want to delete the files from the excel sheet through vba.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this !


    According to your attachment a VBA demonstration as a starting point :

    PHP Code: 
    Sub Demo1()
                 
    Dim BillN&
        
    With Sheet3
            
    For Each Bill In .Evaluate(Replace("C2:C#&B2:B#""#", .UsedRange.Rows.Count))
              If 
    Dir(Bill) > "" Then Kill Bill1
            Next
        End With
            MsgBox 
    "Deletion #  :  " N
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  3. #3
    Registered User
    Join Date
    02-08-2021
    Location
    us
    MS-Off Ver
    365
    Posts
    13

    Re: Hi, try this !

    Dear Marc L

    The above code shows a run-time error '52': Bad file name or number. I need to delete each files in column be which is located at column D folder path. the vba shall run even if there is any error (for example, if the file doesn't exist).

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Delete files from the listed file paths in the table


    As you must see in the code it checks first if the file exists and as it well works with 'normal' files …

  5. #5
    Registered User
    Join Date
    02-08-2021
    Location
    us
    MS-Off Ver
    365
    Posts
    13

    Re: Delete files from the listed file paths in the table

    Hi Marc L,

    The files are existing, still it shows the error.

    Also, "sheet3" is not the actual sheet name, should I change the same with the actual sheet name where the data lies?

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Delete files from the listed file paths in the table


    As I wrote « According to your attachment » Sheet3 is the codename of the Delete List worksheet
    but « as a starting point » you are free to amend the procedure per your will.

    Check the attributes of the file …

+ 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. Delete each file listed in column G
    By nordicdust in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-11-2022, 10:29 AM
  2. [SOLVED] How to delete all files in folder - except few listed files
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-02-2020, 06:27 AM
  3. [SOLVED] Loop through files in folder, email file to listed recipient of file name = cell value
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2017, 03:41 PM
  4. Read File.Paths in selected Folder + open relevant files
    By PatrickMiller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2017, 08:51 AM
  5. Delete all files listed in Column A
    By mkn95u0 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-12-2016, 04:48 PM
  6. Export To Inf file & Zip the Files from the given file paths picking every 10 rows
    By vivekhalder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 03:59 AM
  7. Replies: 3
    Last Post: 05-06-2006, 11:50 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