[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problems adding new spreadsheet to an existing Excel file

Posted on 2004-10-14
4
Medium Priority
?
169 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 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