VBA & Macro Problems

Excel VBA: Delete Specific Worksheets from Multiple Workbooks

Maira MehtabMaira Mehtab Nov 12, 2026 869 views

Question details

The user needs to remove worksheets named Alpha and Beta from approximately 100 Excel workbooks in bulk, or process the Omega worksheets across those files.

Product
Microsoft Excel desktop with VBA macros
Device & OS
not provided
Scenario
The workbooks are stored in one folder and need the same worksheet deletion operation applied automatically instead of editing each file manually.
Observed behavior
There is no reported error; the user needs a batch-processing method for deleting named worksheets from multiple workbooks.
Before you start

Place the target workbooks in one folder and keep the macro workbook outside that folder so it is not processed accidentally. Create a copy of the folder, then confirm the exact worksheet names are Alpha and Beta, including capitalization and spaces.

Solution 1Recommended

Run a VBA macro to delete Alpha and Beta from every workbook

Use this solution when all target Excel files are in one folder and each workbook should be opened, updated, saved, and closed automatically.

The macro searches the selected folder for files matching *.xls*, opens each workbook, checks whether Alpha and Beta exist, deletes them when found, and saves the result. Keep the folder path accurate and leave the trailing backslash in the Windows path.

1
Open the VBA editor

Open a separate macro-enabled workbook in desktop Excel, press Alt+F11 to open the Visual Basic Editor, select Insert > Module, and paste the macro into the new module.

2
Set the folder path

Replace the value of strFolder in the macro with the folder containing the workbooks. For example, use strFolder = "C:\Excel\Test\" and keep the final backslash.

3
Paste and run the batch macro

Paste this code into the module, close the editor, return to Excel, press Alt+F8, select DeleteAlphaBetaFromFolder, and click Run: Sub DeleteAlphaBetaFromFolder() Dim strFolder As String Dim strFile As String Dim wbk As Workbook On Error GoTo ErrHandler Application.ScreenUpdating = False Application.DisplayAlerts = False strFolder = "C:\Excel\Test\" strFile = Dir(strFolder & "*.xls*") Do While strFile <> "" Set wbk = Workbooks.Open(Filename:=strFolder & strFile) On Error Resume Next wbk.Worksheets("Alpha").Delete wbk.Worksheets("Beta").Delete On Error GoTo ErrHandler wbk.Close SaveChanges:=True strFile = Dir Loop ExitHandler: Application.DisplayAlerts = True Application.ScreenUpdating = True Exit Sub ErrHandler: MsgBox Err.Description, vbExclamation Resume ExitHandler End Sub

4
Verify the processed files

Open several workbooks from the folder and confirm that Alpha and Beta are removed while the other worksheets remain. If the files contain formulas, links, or protected sheets, review those results before processing the entire folder.

Process only the intended files: The macro processes every Excel-compatible file matching *.xls* in the specified folder. Move unrelated workbooks elsewhere before running it, or change the file pattern to target a narrower group.

Batch-delete named worksheets with WPS Spreadsheets

WPS Spreadsheets can open compatible Excel workbooks and, in editions with VBA support enabled, run a folder-processing macro to remove Alpha and Beta from multiple files. Use the desktop app, confirm macro permissions, and test the operation on copied files before processing the full folder.

  1. 1. Open WPS Spreadsheets: Launch WPS Office, open a separate macro workbook, and use the Tools or Developer area to open the VBA editor if VBA is available in your edition.
  2. 2. Insert the macro: In the VBA editor, choose Insert > Module, paste the batch-deletion macro, and update the strFolder value to the folder containing the target Excel files.
  3. 3. Allow macro execution: Open Tools > Options or the Security Center, review macro security settings, and allow the macro to run only for the trusted test folder.
  4. 4. Run and verify the batch: Return to WPS Spreadsheets, use the macro dialog to select DeleteAlphaBetaFromFolder, click Run, and inspect several processed workbooks for the expected worksheet changes.
Automates deletion of named worksheets across a folder of workbooksSupports familiar spreadsheet menus and VBA-style workflowsCompatible with Microsoft Excel .xlsx and .xls workbook formatsProvides a lightweight alternative for reviewing and editing large batches of spreadsheets
microsoft office alternative - wps office

Frequently Asked Questions

Can the macro process both .xlsx and .xls files?

Yes. The *.xls* pattern matches common Excel workbook extensions, including .xls, .xlsx, .xlsm, and related formats. Change the pattern if you want to process only one extension.

What happens if a workbook does not contain Alpha or Beta?

The example checks each worksheet separately and ignores a missing sheet, so the workbook can still be saved and closed. Review a sample of the output files after the run.

Why does the macro need a trailing backslash in the folder path?

The macro combines strFolder with the filename returned by Dir. A trailing backslash separates the folder path from the filename, such as C:\Excel\Test\Book1.xlsx.

Can I delete Omega instead of Alpha and Beta?

Yes. Replace the worksheet deletion line with wbk.Worksheets("Omega").Delete. If you need to extract Omega rather than delete it, use the Move or Copy command or create a separate extraction macro.

Why does Excel warn me before deleting a worksheet?

Worksheet deletion is destructive, so Excel normally displays a confirmation dialog. The macro temporarily sets Application.DisplayAlerts = False to prevent one dialog per workbook, then restores alerts when processing ends.