vba clear file code example
Example 1: vba clear a worksheet
Sheet1.UsedRange.ClearContents
Sheet1.UsedRange.ClearFormats
Sheet1.UsedRange.Clear
Sheet1.UsedRange.Delete
With Application
.Calculation = xlManual
.ScreenUpdating = False
Sheet1.UsedRange.Delete
.ScreenUpdating = True
.Calculation = xlAutomatic
End With
Example 2: vba delete file
Function FileExists(ByVal FileToTest As String) As Boolean
FileExists = (Dir(FileToTest) <> "")
End Function
Sub DeleteFile(ByVal FileToDelete As String)
If FileExists(FileToDelete) Then
SetAttr FileToDelete, vbNormal
Kill FileToDelete
End If
End Sub