I am trying to build a macro that will search in the /C:Users/"their username"/Downloads folder to delete any files that have the same saved name, but with different numbers at the end of the file names.
I was able to get the macro to delete a file with no issue, my question is how do I make this "loop" to be delete every file that has the same name in that folder until there are no more remaining?
(I am very new to VBA/macro building and have built this around research online and previous macros)
Here is what I currently have:
Sub killxls()
' killxls Macro
'
' Macro used to delete all "Dock_Activity_*.xls" files
' in "C:\Users\("username")\Downloads\"
'
' Keyboard Shortcut: Ctrl+t
Dim Filename, Pathname As String
Dim Killfile As String
Dim UserName As String
UserName = Environ("username")
Pathname = "C:\Users\" & Environ$("username") & "\Downloads\"
Filename = Dir(Pathname & "Dock_Activity_*.xls")
Killfile = "C:\Users\" & Environ$("username") & "\Downloads\" & "Dock_Activity_*.xls"
Do While Killfile <> ""
KillProperly "Pathname & Killfile"
Killfile = Dir$(Pathname & "Dock_Activity_*.xls")
Loop
End Sub
Public Sub KillProperly(Killfile As String)
If Len(Dir$(Killfile)) > 0 Then
SetAttr Killfile, vbNormal
Kill Killfile
End If
End Sub
Thank you in advance for your help!