Save A Workbook

ou can save the currently selected Excel workbook using either the Save or Save As methods of the Workbook object. Excel has a different workbook object for each workbook you open. You can reference a specific workbook object by name, if you know the name. For example, the code Workbooks( "Sample, xls" ) .Save saves the Sample.xls workbook.

If you do not know the name of the workbook you want to save, you make the workbook the active workbook in Excel, and use the ActiveWorkbook property to save the workbook. For example, the code ActiveWorkbook.Save saves whichever workbook is currently active in Excel.

If the workbook you want to save contains the macro currently running, you can use the ThisWorkbook property: ThisWorkbook.Save. Typically this is the same as the active workbook, but if you open a new workbook during the execution of the macro, the active workbook becomes the new workbook.

To specify how Excel saves the workbook, you need to use the SaveAs method which has several different parameters to customize the way the workbook saves: FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, and Local.

Use the FileName parameter to specify the filename and location where you want to save the workbook. If you omit this parameter value, Excel uses the filename of the workbook as the value for the FileName parameter.

You can use the FileFormat parameter to specify the file format for the saved workbook. You can save the workbook using any of the file formats Excel supports by listing one of the XlFileFormat constant values. See Appendix A for a list of the XlFileFormat constant values.

SAVE A WORKBOOK

SAVE A WORKBOOK

'—n Create a new subroutine

—0 Type Workbooks(1).SaveAs., replacing Workbooks(l) with the workbook that you want to save.

■ You can also use the Save method by typing Workbooks(1).Save and skipping the other steps.

—0 Type Workbooks(1).SaveAs., replacing Workbooks(l) with the workbook that you want to save.

■ You can also use the Save method by typing Workbooks(1).Save and skipping the other steps.

0 0

Post a comment