Quantcast
Channel: Microsoft Community - Super Fresh
Viewing all articles
Browse latest Browse all 1237235

Help: How could I delete a file, based on a cell value in Excel VBA?

$
0
0

Hi,

I'm trying to delete a file, running VBA code where:

based on a cell value, the program looks for a file with the same name and then deletes it.

Here it looks for INACTIVE files, moves 1 cell to the right and then deletes the appropriate files from a folder.

This is the code I've implemented so far:

Sub delete_INACTIVE_files()

Dim r As Range
Dim path As String
Dim file_name As String
Dim actsh As Worksheet


Set actsh = ActiveSheet

Application.ScreenUpdating = False

Set r = ActiveSheet.Cells(1, 1)

Do Until r = ""

    If UCase(r.Value) Like "INACTIVE" Then
    ActiveCell.Offset(0, 1).Select

'I don't know how to insert the file name in the kill function

    Kill ("C:\Users\NikolouzosD\AppData\Local\Temp\vbakillfunction\" & file_name)

   
     

    End If

Set r = r.Offset(1, 0)

Loop

End If

End Sub


Viewing all articles
Browse latest Browse all 1237235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>