Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HELP- How can I start off excel with a new worksheet: sheet1, everytime?


Hi,
I created a excel workbook with many worksheets inside. But I would
like to reset(or delete all worksheets inside) the workbook and left
only with a new empty worksheet: Sheet1, everytime I re-start the
workbook. Any Macro code which I can use to do that??

Thanks alot :)


--
Acube
------------------------------------------------------------------------
Acube's Profile: http://www.excelforum.com/member.php...o&userid=29734
View this thread: http://www.excelforum.com/showthread...hreadid=522506

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default HELP- How can I start off excel with a new worksheet: sheet1, everytime?

The following is a generic process to create a new workbook with as many
sheets as required, place the number required in the function parameter,
e.g.
NewBook(1) for one sheet or NewBook(8) for eight sheets etc.

'============================================
' call the create function
' enter number of worksheets in new workbook
'============================================
Sub testwb()
If NewBook(1) Then
MsgBox "Workbook Created Successfully"
Else
MsgBox "Workbook Create Failed"
End If
End Sub

'============================================
' function to create a new workbook
' returns true if successful
'============================================
Function NewBook(xsheets As Integer) As Boolean

NewBook = False

' test within range
If xsheets = 1 And xsheets <= 256 Then

' create new workbook
Dim NewWB As Workbook
Workbooks.Add
Set NewWB = ActiveWorkbook

' clean out the unwanted worksheets max= xsheets
Dim ws As Integer
With NewWB
For ws = .Sheets.Count To 1
If ws xsheets Then Sheets(ws).Delete
Next
End With

' if not enough sheets add them
With NewWB
Do While .Sheets.Count < xsheets
.Sheets.Add after:=.Sheets(.Sheets.Count)
Loop
End With

' set return value
NewBook = True

End If

End Function



--
Cheers
Nigel



"Acube" wrote in
message ...

Hi,
I created a excel workbook with many worksheets inside. But I would
like to reset(or delete all worksheets inside) the workbook and left
only with a new empty worksheet: Sheet1, everytime I re-start the
workbook. Any Macro code which I can use to do that??

Thanks alot :)


--
Acube
------------------------------------------------------------------------
Acube's Profile:

http://www.excelforum.com/member.php...o&userid=29734
View this thread: http://www.excelforum.com/showthread...hreadid=522506



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
How do I print a specific worksheet everytime? Trevor Excel Discussion (Misc queries) 1 May 10th 10 08:24 PM
printing a specific worksheet everytime Trevor Excel Discussion (Misc queries) 1 May 10th 10 02:40 PM
How to start Excel on a specific Worksheet. JMay Excel Discussion (Misc queries) 6 February 21st 07 05:45 AM
Worksheet that appears on start of Excel Lou Excel Discussion (Misc queries) 1 April 11th 06 08:08 PM
start a macro everytime excel opens Jeff Excel Programming 3 July 16th 04 05:55 PM


All times are GMT +1. The time now is 01:23 AM.

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"