Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Excel Worksheet 2

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Hi Folks,

I am creating an Excel worksheet from a VBScript program. The first thing I do is create a new worksheet called summary. Then I delete the three default worksheets (Sheet1, Sheet2 and Sheet3).

However the program then adds about another 30 worksheets which all contain data. The problem is that it adds these worksheets before my summary worksheet and I want my summary worksheet to be the first one.

Is there any way that I can specify that the worksheets are to be added after the summary sheet?

Mighty
 
Something like this ?
xlApp.WorkSheets.Add , xlApp.Worksheets(Worksheets.Count)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Tried doing things like that but no luck

Mighty
 
Any chance you could post what you've tried ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Well at the moment I just have:

set stockSheet = workBook.WorkSheets.Add

That puts it before the previous sheet. But I have tried:

set stockSheet = workBook.WorkSheets.Add(, "Summary")
set stockSheet = workBook.WorkSheets.Add(, workBook.WorkSheets.count)

Don't know??

Mighty
 
[tt]workBook.sheets("Summary").move workbook.sheets(1)
[/tt]
 
The following should work:
Set stockSheet = NameOfWorkbookObject.Sheets.Add( , NameOfWorkbookObject.WorkSheets(Worksheets.Count))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

That didn't work for me - just got an error message.

tsuji,

That works to a certain degree. It gets my summary sheet first. However, ideally I would like the sheets to be added after the previous sheet every time I add one rather than before.

Mighty
 
And this ?
Set stockSheet = workBook.Sheets.Add( , workBook.WorkSheets(workBook.WorkSheets.Count))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

That worked a treat. Thanks.

Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top