Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determining if a worksheet exists within a workbook
I have a macro that creates a new excel workbook and adds a variable
number of new worksheets to the new workbook. I would like to delete any excess worksheets from this newly created workbook (ie: Default "Sheet1", "Sheet2", "Sheet3"). I can add code to delete these sheets: Sheets("Sheet1").Delete Sheets("Sheet2").Delete etc... but, the number of sheets added to a new excel workbook will vary depending on the individual user's Excel defaults. 1. Is there a way to determine if a sheet exists, and if it does, delete it, ie: If Sheets("Sheet1").Exists then Delete Sheets("Sheet1"). 2. Is there a way to within a macro force a new workbook to open with a set number of sheets? Any help would be appreciated! Thanks, Cory |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determining if a worksheet exists within a workbook
Hi.
Sub AddWkbOneSheet() Workbooks.Add xlWBATWorksheet End Sub Sub AddWkbFiveSheets() Dim Exnb As Long Exnb = Application.SheetsInNewWorkbook Application.SheetsInNewWorkbook = 5 Workbooks.Add Application.SheetsInNewWorkbook = Exnb End Sub Alain CROS. -----Original Message----- I have a macro that creates a new excel workbook and adds a variable number of new worksheets to the new workbook. I would like to delete any excess worksheets from this newly created workbook (ie: Default "Sheet1", "Sheet2", "Sheet3"). I can add code to delete these sheets: Sheets("Sheet1").Delete Sheets("Sheet2").Delete etc... but, the number of sheets added to a new excel workbook will vary depending on the individual user's Excel defaults. 1. Is there a way to determine if a sheet exists, and if it does, delete it, ie: If Sheets("Sheet1").Exists then Delete Sheets("Sheet1"). 2. Is there a way to within a macro force a new workbook to open with a set number of sheets? Any help would be appreciated! Thanks, Cory . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Already exists on the destination workbook | Excel Worksheet Functions | |||
Create Worksheet BUT If It Already Exists... | Excel Discussion (Misc queries) | |||
Determining if a value already exists in column(s) | Excel Discussion (Misc queries) | |||
check if worksheet exists | Excel Worksheet Functions | |||
check if worksheet exists | Excel Programming |