index > Visual Studio Tools for Office > Excel SaveAs() method

Excel SaveAs() method

I'm having trouble saving a workbook. I show a SaveFileDialog, the user specified where he wants to save the file, and where. When the user clicks on Save button, I say SaveAs... and do something else with the file (after the file is saved). Anyway, that's what it should do.

My code for saving is this:

this.SaveAs(fileName, Excel.XlFileFormat.xlXMLSpreadsheet, missing, missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missing, false, missing, missing, true);

It simply doesn't save the xls file. It doesn't throw any exception, but the file is not at the destination path.

Does anybody have any idea why?

Sandrina

Hi,

Your code looks correct and it seems to work for me under test if I assign an arbitrary path to fileName. So it would seem that either your code isn't getting executed at all, fileName isn't evaluating to what you expect (so the file is getting saved somewhere else), or the file is getting saved where you expect, but you aren't seeing it.

In other words, you probably need to systematically check your assumptions. Start by putting a breakpoint on the offending line to confirm that it executes. If it gets hit, evaluate fileName and confirm that it is what you expect. When you go to try to find it on disk, try a few different methods; i.e. explorer, command prompt, write some code to call Open using the exact same path...

If the above suggestions don't help, please repost and let us know what fileName is evaluating to when you call SaveAs as well as describing how you are going about confirming the file's existence on disk.

Sincerely,

Geoff Darst

Microsoft VSTO Team

Geoff Darst - MSFT

OK... When user clicks Save on the dialog form, the filename is something like "C:\\Demand1.xls". Yes, the execution gets to the SaveAs method, and it passes it without any problem (it doesn't throw any exception)... Just that there is no saved file... Yes, I tried to open it after from code, but File.Open(fileName) method throws FileNotFound exception (I'm not sure whether that's the right exception, but that's it).

However, when I use this.SaveCopyAs(fileName) method, it saves without a problem.... Only SaveAs doesn't work. I mean, I solved my problem with SaveCopyAs, but I still wonder why won't it save...

Thanks for your time, I really appreciate it.

Aleksandra

Sandrina

Interesting. I wonder if you are doing something that is locking the original document file so that Excel can't release the storage? That would be the only difference between SaveAs and SaveCopyAs. Both cases make a copy, but only the former tries to reopen the new document. I'm guessing that the SaveAs may well have worked and that you would probably have a copy of the document in your temp directory--though it might not have a meaningful name.

I'm not sure what would cause this. You might just start pulling blocks of code out of your project to try to isolate the problem.

Sincerely,

Geoff Darst

Microsoft VSTO Team

Geoff Darst - MSFT
reply 4

You can use google to search for other answers

 

More Articles

• ListObject binding
• Visual Studio Version
• VSTO 3.0 and Vista Beta 2?
• Microsoft.Office.Tools.Word.XMLNode.ContextLeave: Problems with s...
• VSTO Word doc design error when adding an numericupdn
• Conflict between Word and Outlook
• VSTO2005-Word. Only want the code-behind to run from Template not...
• Getting Memory Erros with Add-In
• ServerDocument failure dependant on the directory file is in....
• Deploying Shared AddIns created in C#.NET which uses web services
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Building an outlook add-in
• Smart Docs in SharePoint
• newbie in smart clients
• Excel & VSTO problem
• Help Needed: Smart Tags in Excel and Rec
• Cannot find wrapper assembly for type li
• Issue with MS Project localization.
• Share single dataset across worksheets
• How to read data from a word document wi
• Select worksheet explicitly
• Addin(with VSTO 2005 developed) doesn't
• Word2007 Add-In: Can I customize the Wor
• Can a VSTO 2005 Excel Application be sta
• How to improve cold start with Outlook a
• How to get Office project type in MS VS

Hot Articles

• Preventing other applications to attach
• Developing Add-in for Office XP: Open Is
• How can I use the Page interface in the
• Difficulties running Word Add-ins with V
• TrackChanges Issue
• Dynamically installing/loading and unins
• problems with deployment of VSTO 2005 Ex
• VSTO Deployment
• Outlook plugin problem.
• Conversion problem
• More VSTO install woes
• PInvokeStackImbalance caused by Smart Ta
• VSTO Word Document Code Not Running
• custom macros could not be initialized e
• How to insert a Date Picker into a MS Ex

Recommend Articles

• help with excel
• DLL VB express 2005 in Excel
• Actions pane on "regular" Exce
• C# with Excel -- How to select a sheet?
• VSTO -- vs. Visual Studio/Basic 2005 Exp
• OLE err in VST2003 Startup Wizard
• Displaying an icon on a commandbarbutton
• Excel 2003 copy method failed
• How do I deploy other apps w/ Outlook So
• Autosave
• Unit testing a .NET app hosted within Of
• imageMso attribute
• VstoSmartTags from a COM Add-In
• Where is VSTO Installed?
• strange error in excel