Worksheets Add fails with SP1 of Excel 2003

G

Guest

Adding a new worksheet using the Worksheets Add method throws an exception
with error code 0x80010105 (RPC_E_SERVERFAULT - "The server threw an
exception.").
The code (in C++) looks like this:

Worksheets sheets;
sheets = book.GetWorksheets();
sheet = sheets.Add(covOptional, covOptional, covOptional, covOptional);

This code works without problems with Excel 2000 and 2002.
It also worked with Office 2003 without SP1. After installing SP1 however
the program fails the way described above.

I am running Windows XP SP1 + Office Professional Edition 2003.
Thanks
 
G

Guest

After some investigation the problem seems to be related to the fact that
Excel is not the active view, when the Worksheet is added. With SP1 installed
this method now fails.

I produced a small example program, an MDI application created with MFC,
where one of the views is an in-place activated Excel workbook.
A command in the File menu calls the Worksheets Add method on the Excel
view. The example demonstrates that this method fails if Excel is not the
active view.
This worked for all previous version of Excel, but not anymore with SP1
installed.

Unfortunately the workaround to always activate the Excel view during this
operation, is not possible in our real application.
 
G

Guest

adding this for posterity mostly because i have the identical problem and
cant find any documentation anywhere:
this code replaces the "sheets.add" code that throws the error in excel 2003
with sp1:
'xlb is the workbook
xlb.Parent.Windows(xlb.Name).Visible = True
Set xls = xlb.Sheets.Add(After:=xlb.Sheets(xlb.Sheets.Count))
xlb.Parent.Windows(xlb.Name).Visible = False

i havent tested it to see if it works in excel 97-2002, but it should
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top