Save Workbook In Format Specified By User

You can request the name, location, and format for saving a workbook file from the user of your macro with the GetSaveAsFilename method. Using this method displays the Save As dialog box into which the user entered information for saving the file. The dialog box does not save the workbook file; instead, Excel returns the user specified information to the variable assigned to the statement. To save the file, you use the SaveAs method. See the section "Save a Workbook" for more information. The GetSaveAsFilename includes several optional parameters for customizing the appearance of the Save As dialog box: InitialFilename, FileFilter, FilterIndex, and Title.

You use the InitialFilename parameter to suggest a different name, other than the active workbook default, in the File name field.

You use the FileFilter parameter to allow only certain file formats for saving the workbook file. If you omit this parameter, Excel lists all formats available. If you include this parameter, you need two different string parts. The first, a text description of the file format, displays in the Save as type drop-down list box . The second indicates the MS-DOS wildcard statement for the file type.

You use the FilterIndex parameter to indicate the default file filtering option which depends on the options you specify for the FileFilter parameter. You specify a filter value listed between 1 and the number of filters. If you omit this parameter, VBA uses the first filter specified as the default value. You use the Title parameter to customize the name of the dialog box.

SAVE WORKBOOK IN FORMAT SPECIFIED BY USER

SAVE WORKBOOK IN FORMAT SPECIFIED BY USER

—n Create a new subroutine.

0 Type UserFile =

Application.GetSaveAs

Filename().

0 Type Title:="Dialog box text" within the parentheses, replacing "Dialog box text" with the text for header of the dialog box.

—n Create a new subroutine.

^0 Type Dim UserFile As Variant, replacing UserFile with the variable to receive name for saving file.

0 Type UserFile =

Application.GetSaveAs

Filename().

^Q Type FileFilter:="Excel Workbooks (*.xls), replacing *.xls within the parentheses with the type of file to save.

■ To save only the Excel Workbooks, you can type "Excel Workbook (*.xls), *.xls".

0 Type Title:="Dialog box text" within the parentheses, replacing "Dialog box text" with the text for header of the dialog box.

0 0

Post a comment