Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Already exists on the destination workbook ChrisP Excel Worksheet Functions 3 July 11th 08 08:13 PM
Create Worksheet BUT If It Already Exists... Dave Excel Discussion (Misc queries) 2 October 30th 07 11:13 PM
Determining if a value already exists in column(s) Rookie_User Excel Discussion (Misc queries) 0 October 3rd 06 05:32 PM
check if worksheet exists joeeng Excel Worksheet Functions 3 September 7th 05 06:49 PM
check if worksheet exists Craig Wilks Excel Programming 2 July 10th 03 04:07 AM


All times are GMT +1. The time now is 02:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"