LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Running code when a worksheet opens

I have built some code asking the user how many worksheets he would like to
add to a workbook with 1 visible worksheet. It is attached to a button and I
now need to put that code in a property such as "On Open" (I'm better with
Access), so when the worksheet opens, the first question is "How many...".
I've read some of the other posts, but can't find the property/ies they refer
to.

So far, I have:
------------------------------------
Private Sub Worksheet_Open()
Dim NumSheets, x, y

y = Worksheets.Count
NumSheets = InputBox("How many sheets to add?")
If NumSheets = Empty Then
End
Else
For x = 1 To NumSheets
Sheets("1").Select
Sheets("1").Copy After:=Sheets(1)
y = y + 1
ActiveSheet.Name = y - 2
Next x
End If
End Sub
------------------------------------

The reason I have "y - 2" above is because I also have 2 hidden worksheets
(used for data validation). If not "Private Sub Worksheet_Open()", then
where?

Thanks in advance for any help.
 
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
Running Code on Hidden Worksheet Steve C Excel Programming 2 February 13th 07 06:52 PM
Refer to the worksheet containing the current running code [email protected] Excel Programming 2 November 30th 06 10:14 AM
how to prevent code running when in a worksheet code Corey Excel Programming 5 August 13th 06 08:52 AM
Running VBA Code not written within the currrent worksheet DMB Excel Programming 2 September 6th 05 05:58 PM
Running Code in an XLA from a Worksheet Chrissy[_4_] Excel Programming 6 October 11th 03 11:27 PM


All times are GMT +1. The time now is 06:02 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"