Dear Gurus
With your help I have managed to put the macro below together. Now I want to enter the sheet name to be deleted into a input box. The code at the moment asks me the sheet name with every file it opens. how do I change this to only enter it once?
Thank you
Es
Sub LoopAllExcelFilesInFolderDeleteSpecificSheetadvisorDashboard()
'PURPOSE: To loop through all Excel files in a user specified folder and perform a set task on them
'SOURCE: www.TheSpreadsheetGuru.com
Dim myPath As String
Dim myExtension As String
Dim myFile As String
Dim wb As Workbook
Dim ws As Worksheet
Dim myValue As Variant
'Retrieve Target Folder Path From User
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select A Target Folder"
If .Show Then
myPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
If Right(myPath, 1) <> "" Then
myPath = myPath & ""
End If
'Optimize Macro Speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'Target File Extension (must include wildcard "*")
myExtension = "*.xls*"
'Target Path with Ending Extension
myFile = Dir(myPath & myExtension)
'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(FileName:=myPath & myFile)
'Test whether sheet exists
Set ws = Nothing
On Error Resume Next
myValue = InputBox("Sheet Name")
Set ws = wb.Worksheets(myValue)
If ws Is Nothing Then
'Sheet doesn't exist - close workbook without saving it
wb.Close SaveChanges:=False
Else
'Delete sheet without displaying a warning
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
'Save and Close Workbook
wb.Close SaveChanges:=True
End If
'Get next file name
myFile = Dir
Loop
'Message Box when tasks are completed
MsgBox "Task Complete!", vbInformation
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub