KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 478
- Office Version
- 2016
- Platform
- Windows
Hi everyone
I am using this VBA code to delete PNG files in a subfolder.
It won't even though the subfolder address is in I3. And look like this D:\DNBR 2025\Rejseafregning\Bilag
Can anyone help.
Any help would be appreciated
Best regards Klaus W
I am using this VBA code to delete PNG files in a subfolder.
It won't even though the subfolder address is in I3. And look like this D:\DNBR 2025\Rejseafregning\Bilag
Can anyone help.
Any help would be appreciated
Best regards Klaus W
VBA Code:
Sub Del()
Dim path As String
path = Range("I3")
If Right(path, 1) <> "\" Then
path = path & "\"
End If
Dim exceptedFile As String
exceptedFile = "B1.png"
Dim currentFile As String
currentFile = Dir(path & "*.*", vbNormal)
While (Len(currentFile) > 0)
If LCase(currentFile) <> LCase(exceptedFile) Then
Kill path & currentFile
End If
currentFile = Dir
Wend
MsgBox "Bilag slettet!", vbExclamation
End Sub