Solved

Problems adding new spreadsheet to an existing Excel file

Posted on 2004-10-14
4
153 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
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 200 total points
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
also note the difference in the code - using 'worksheet' instead of 'sheet'
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now