Problems using SaveAs and SaveCopyAs

P

PromisedOyster

We have a C# application that is using the Excel object model via
Interop.

The code below works fine for an existing workbook, ie one that you
have opened up (or saved), but if you open up Excel, click the New
button, enter some data and then run the program below, an Exception is
thrown:

Exception for HRESULT: 0x800A03EC on the call to SaveCopyAs


object missing = System.Reflection.Missing.Value;
object o =
System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
Excel._Application excelApp = o as Excel._Application;

// connect to current Excel workBook
Excel.Workbook workBook = excelApp.ActiveWorkbook;

if (workBook == null)
{
throw new ApplicationException("No workbook is currently defined");
}

// get temp file name to save document off to
string fileName = "temp.xls";
workBook.SaveCopyAs(fileName);
workBook.Close (missing
,missing
,missing);


Is there a workaround, I have tried using the SaveAs method but to no
avail.
 

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