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: 6
Default Trouble Adding Worksheet via VBScript

I'm having trouble adding a Worksheet to a Workbook via VBScript. I'm
using an ASP.NET page to generate a few tables. I'm then attempting
to "export" those tables to Excel via the script below. I get an
error on the oBook.Worksheets.Add line, the error telling me "Add
Method of Sheets class failed". Can anyone tell me why?

<script language="vbscript"
dim i
i = 1
Dim oXL, oBook, oSheet, x
Set oXL = CreateObject("Excel.Application")
Set oBook = oXL.Workbooks.Add
for each childobj in window.Form1.children
If Instr(1, childobj.outerhtml, "<TABLE") 0 Then
If i 3 then
oBook.Worksheets.Add NULL, oBook.WorkSheets(i-1), 1
End If
oBook.HTMLProject.HTMLProjectItems("Sheet" & i).Text =
childobj.outerhtml
i = i + 1
End If
Next
oBook.HTMLProject.RefreshDocument
oXL.Visible = true
oXL.UserControl = true
</script

When I use the code below, I have no problems:

Set oXL = CreateObject("Excel.Application")
Set oBook = oXL.Workbooks.Add
oBook.Worksheets.Add NULL, oBook.WorkSheets(3), 1

oBook.WorkSheets(1).Name = "Number 1"
oBook.WorkSheets(2).Name = "Number 2"
oBook.WorkSheets(3).Name = "Number 3"
oBook.WorkSheets(4).Name = "Number 4"

oXL.Visible = true
oXL.UserControl = true

Help!

Dan

 
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
trouble adding addins jc Excel Discussion (Misc queries) 0 December 23rd 09 12:15 AM
Worksheets.add in VBScript overwrites existing worksheet donparkerjr Excel Worksheet Functions 3 November 9th 06 07:09 PM
Trouble with VB since adding a macro Susan Excel Programming 1 April 11th 06 05:13 PM
trouble adding to list. jeramie[_2_] Excel Programming 2 March 13th 06 08:31 AM
How to move worksheet from vbscript Robert Stober Excel Programming 1 October 9th 03 10:19 AM


All times are GMT +1. The time now is 10:21 AM.

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

About Us

"It's about Microsoft Excel"