John,
Bret's answer is by far the easiest! However, in the event that you find yourself actually needing to add a worksheet...
Here's the syntax (Foxified, from the Excel VBA .CHM):
oBook.Worksheets.Add(oBefore, oAfter, nCount, nType)
If you pass no parameters, it the new worksheet is placed just before whatever sheet is active (e.g. oBook.ActivSheet). Otherwise, pick ONE of the first two parameters...EITHER oBefore or oAfter -- not both (remember, VB has named parameters, which makes it much easier to understand). You must pass an *object* here. It seems more natural to pass "2" as the first parameter to get a new worksheet before the second sheet. However, you have to pass the OBJECT...as in:
oBook.Worksheets.Add(oBook.Worksheets[2])
If you want to add it AFTER the third worksheet, use:
oBook.Worksheets.Add(, oBook.Worksheets[3])
Note that the first parameter is blank.
nCount tells how many sheets you want added; thankfully it's a normal numeric value. nType is for Excel's backward compatibility, so you don't need to use it--ignore it.
Of course, Bret's answer is on the mark, if you know exactly how many you need.
- della
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only