Hi all,
I'm trying to build a VBA which will delete a sheet with a predetermine name from each workbook in the selected folder.
This code will be placed in a "Master Sheet" from which, when it will be started, will open one by one each worksheet in a given folder. If there is a sheet in the opened workbook with certain name (which will be filled in a list in the "Master Sheet"), the sheet will be deleted, and the workbook will be saved.
I've start preparing the code, but it does not save teh file. Can you advise where do i make the mistake i it?
Thank you.
Igor
Sub DeleteXSheetInAWorkbok()
Application.DisplayAlerts = False
DeleteThis = ActiveSheet.Range("A1")
FileType = "*.xlsb*"
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path
.AllowMultiSelect = False
If .Show = -1 Then
FilePath = .SelectedItems(1) & "\"
Else
Exit Sub
End If
End With
Curr_File = Dir(FilePath & FileType)
Do Until Curr_File = ""
Set FldrWkbk = Workbooks.Open(FilePath & Curr_File, False, True)
For Each Sheet In FldrWkbk.Sheets
If Sheet.Name = DeleteThis Then
Sheet.Delete
FldrWkbk.Save
End If
Next Sheet
FldrWkbk.Close
Curr_File = Dir
Loop
Set FldrWkbk = Nothing
Application.DisplayAlerts = True
End Sub
Bookmarks