?
Solved

Problems adding new spreadsheet to an existing Excel file

Posted on 2004-10-14
4
Medium Priority
?
164 Views
Last Modified: 2010-04-23
I keep receiving the following error whenever I try to add a new Spread Sheet to an existing Excel File.
Exception from HRESULT: 0x800A03EC.
         at Excel.Sheets.Add(Object Before, Object After, Object Count, Object Type)
         at CamShaft.Form1.AddNewExcelSheet() in <My Program Name>
Here is my code:

Dim excelApp As Excel.Application
Dim excelBook As Excel.Workbook
Dim excelBook2 As Excel.Workbook
Dim excelSheet As Excel.Worksheet

excelApp = New Excel.Application
If TempType.Text = "T" Then
   excelBook = excelApp.Workbooks.Open(TestFile.Text)
ElseIf TempType.Text = "R" Then
   excelBook = excelApp.Workbooks.Open(RealFile.Text)
End If
excelSheet = excelBook.Sheets.Add
excelSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape

Any help would be appreciated.
0
Comment
Question by:DEIIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 600 total points
ID: 12308646
try this change, from:

excelSheet = excelBook.Sheets.Add


to:

excelSheet = excelBook.Sheets.Add(After:=Worksheets(Worksheets.Count))


That will add the new shett AFTER the last sheet in the current set.

AW
0
 
LVL 8

Assisted Solution

by:bramsquad
bramsquad earned 150 total points
ID: 12309212
add the sheet, then select the sheet

replace this

excelSheet = excelBook.Sheets.Add

with this

excelBook.Worksheets.Add()
excelSheet = excelBook.Worksheets.Item(SheetIndexNumber)

~b
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 12309222
also note the difference in the code - using 'worksheet' instead of 'sheet'
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question