Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Save Workbooks

Updated: July 2008

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

There are several ways to save a workbook. You can save a workbook without changing the path. If the workbook has not been saved before, you should save the workbook by specifying a path. Without an explicit path, Microsoft Office Excel saves the file in the current folder with the name it was given when it was created. You can also save a copy of the workbook without modifying the open workbook in memory.

To save a workbook associated with a document-level customization

  • Call the Save method of the ThisWorkbook class.

    this.Save();
    

To save the active workbook in an application-level add-in

  • Call the Save method to save the active workbook. To use the following code example, run it in the ThisAddIn class in an application-level project for Excel.

    this.Application.ActiveWorkbook.Save();
    

You can save the specified workbook to a new location or with a new name, optionally specifying a file format, a password, an access mode, and more.

NoteNote:

You might want to set the DisplayAlerts property to False before saving the workbook with a new path because saving in some formats requires interaction. Setting this property to False causes Excel to use all defaults.

To save a workbook associated with a document-level customization

  • Call the SaveAs method of the ThisWorkbook class. To use the following code example, run it in the ThisWorkbook class.

    this.SaveAs(@"C:\Book1.xml", missing,
        missing, missing, missing, missing, Excel.XlSaveAsAccessMode.xlNoChange,
        missing, missing, missing, missing, missing);
    

To save the active workbook in an application-level add-in

You can save a copy of the workbook to a file without modifying the open workbook in memory. This is useful when you want to create a backup copy without modifying the location of the workbook.

To save a workbook associated with a document-level customization

  • Call the SaveCopyAs method of the ThisWorkbook class. To use the following code example, run it in the ThisWorkbook class.

    this.SaveCopyAs(@"C:\Book1.xls");
    

To save the active workbook in an application-level add-in

  • Call the SaveCopyAs(Object) method to save a copy of the active workbook. To use the following code example, run it in the ThisAddIn class in an application-level project for Excel.

    this.Application.ActiveWorkbook.SaveCopyAs(@"C\Book1.xls");
    

Interactively canceling any of the methods that save or copy the workbook raises a run-time error in your code. For example, if your procedure calls the SaveAs method but does not disable prompts from Excel, and your user clicks Cancel when prompted, Excel raises a run-time error.

Date

History

Reason

July 2008

Added a code example that can be used in an application-level add-in.

Customer feedback.

Community Additions

ADD
Show:
© 2015 Microsoft