Hi Excel Experts
I have applied this VBA macro to delete empty excel files in a folder path
This VBA macro is working in my excel 2007 version
Here when I applied this macro in my another pc of excel 2016 version
Then this VBA macro is not deleting any empty excel files in that folder path i have given
And one more query
How to add multiple excel extension in this macro
I have applied this VBA macro to delete empty excel files in a folder path
This VBA macro is working in my excel 2007 version
Here when I applied this macro in my another pc of excel 2016 version
Then this VBA macro is not deleting any empty excel files in that folder path i have given
And one more query
How to add multiple excel extension in this macro
VBA Code:
Sub DeleteEmptyFiles()
Dim FolderPath As String, Filename As String, wb As Workbook
Dim ws As Worksheet, boolNotEmpty As Boolean
Dim previousSecurity As MsoAutomationSecurity
FolderPath = "Enter the folder path here" 'Take care to end the folder path in "\"
'Otherwise, build the file full name inserting "\"
Filename = Dir(FolderPath & "*.xlsm*")
Do While Filename <> ""
previousSecurity = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Set wb = Workbooks.Open(Filename:=FolderPath & Filename)
Application.AutomationSecurity = previousSecurity
boolNotEmpty = False
For Each ws In wb.Worksheets
If WorksheetFunction.CountA(ws.UsedRange) > 0 Then
boolNotEmpty = True: Exit For
End If
Next ws
wb.Close False
If Not boolNotEmpty Then Kill FolderPath & Filename
Filename = Dir()
Loop
End Sub