ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems using SaveAs and SaveCopyAs (https://www.excelbanter.com/excel-programming/335002-problems-using-saveas-savecopyas.html)

PromisedOyster

Problems using SaveAs and SaveCopyAs
 
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.GetActiveOb ject("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.



All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com