XLA routines: EE_DeleteFile

Nick's picture
EE_DeleteFile deletes a file if it exists.
Sub EE_DeleteFile(strFilePath As String, Optional blnShowMsg As Boolean = False)
'- takes file path
'- deletes file
'- does not error if file does not exist
'- does error if file is locked
'http://excelexperts.com/xla-routines-eeDeleteFile    for updates on this sub routine

    With CreateObject("Scripting.FileSystemObject")
        If .FileExists(strFilePath) Then
            On Error Resume Next
                .deletefile strFilePath
                If Err.Number <> 0 And blnShowMsg = True Then
                    MsgBox Err.Description, vbCritical, "File locked"
                End If
            On Error GoTo 0
        End If
    End With
End Sub