Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
trouble adding addins | Excel Discussion (Misc queries) | |||
Worksheets.add in VBScript overwrites existing worksheet | Excel Worksheet Functions | |||
Trouble with VB since adding a macro | Excel Programming | |||
trouble adding to list. | Excel Programming | |||
How to move worksheet from vbscript | Excel Programming |