DrLeary

Hi!

I'm trying to save the currently opened Workbook using the SaveAs method as shown here http://msdn2.microsoft.com/en-us/library/h1e33e36(VS.80).aspx but it keeps throwing this exception:

"Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))"

So I tried using the Save method, which takes no parameters, but the same result=( This is running from a shared add-inn and I got Word 2007 to save it's open document just fine. So why is Excel giving me grief Here is the code:

Code Block

//SaveDocument
private void SaveDocument(string docName)
{
try
{
object missing = System.Reflection.Missing.Value;

string strTempPath = Application.Utilities.GetApplicationFolder() + "\\Temp";
if (!Directory.Exists(strTempPath))
Directory.CreateDirectory(strTempPath);

if (AxessRibbon.Connect.HostApplication == "Word")
{
object fileName = strTempPath + "\\" + docName + ".docx";
AxessRibbon.Connect.WordApp.ActiveDocument.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
else if(AxessRibbon.Connect.HostApplication == "Excel")
{
object fileName = strTempPath + "\\" + docName + ".xlsx";
//AxessRibbon.Connect.ExcelApp.ActiveWorkbook.Save();
AxessRibbon.Connect.ExcelApp.ActiveWorkbook.SaveAs(fileName, Excel.XlFileFormat.xlWorkbookNormal, missing, missing, false, false, Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
}
else if (AxessRibbon.Connect.HostApplication == "PowerPoint")
{
string fileName = strTempPath + "\\" + docName + ".pptx";
AxessRibbon.Connect.PowerPointApp.ActivePresentation.SaveAs(fileName, PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,MsoTriState.msoTrue);
}
}
catch(Exception ex)
{
string strTekst = "An unexpected error occured while saving the document to the local harddrive:\n" + ex.Message + "\nStackTrace:\n" + ex.StackTrace;
Application.Messages.NewMessage(Application.Messages.MessageTypes.Exception, strTekst, "MyTaskPane.SaveDocument", MessageBoxButtons.OK, this.ShowExceptions, this.LogExceptions);
}
}




Re: Visual Studio Tools for Office Excel Save and SaveAs method throws exception...

Cindy Meister

Managed Add-ins created not using VSTO aren't supported in this forum. For such questions you should ask in the COM_Add_ins newsgroup

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.office.developer.com.add_ins&lang=en&cr=US

but have you searched the error message in the Knowledge Base For example

http://support.microsoft.com/kb/320369/en-us






Re: Visual Studio Tools for Office Excel Save and SaveAs method throws exception...

DrLeary

I don't get it...what's the difference between a VSTO add-in and a "normal" add-inn If you follow the link I posted the article clearly starts with the words "Visual Studio Tools for the Microsoft Office System"...And it's under the VSTO section of MSDN... But okay, I will look into those links you posted. Sorry for all these posts in the wrong forum, but I figured VSTO would be the place to ask=)

Edit: It was a problem with the CultureInfo and not having the right language pack, just as described in the link you posted. Thank you very much!=)






Re: Visual Studio Tools for Office Excel Save and SaveAs method throws exception...

Cindy Meister

Glad the answer was on-target :-) It's always difficult, trouble-shooting such general error messages...

The scope of this forum is technically limited to the VSTO technology. A VSTO Add-in builds on the Shared Add-in template you're using, but it changes certain things, so what applies to a Shared Add-in doesn't necessarily apply to a VSTO Add-in, and vice-versa. As soon as a question comes up about Add-in behavior, it's "safer" to send you to the more topically correct venue. (Sometimes, there are folks here who are conversant with both types of Add-in, other times not.)

Practically, since there is no forum for Office automation - that is all in the newsgroup interface - we'll also answer questions in these areas, as long as the technical expertise is available. This has to come from volunteers / lurkers / forum regulars, as the MSFT folks here are VSTO-technology and not Office experts.When I have time, Word questions get answered, for example :-) In over a year, I can't remember having seen a Powerpoint person here, so we immediately re-route PPT questions to the newsgroup, where we know there are some MVPs conversant in .NET automation.

On the whole, we try to strike a balance between keeping the forum on-topic and making sure people get the assistance they need to get on with their work.