Getsaveasfilename Save File Example

Source: Internet
Author: User
Tags save file

Getsaveasfilename is called through application, and application is used through the VBA environment, so this example gives you the example code that calls the Save As dialog box in Excel.

Its format is as follows:

Dim Filename as String

Filename = Application.getsaveasfilename (filefilter:= "file name, *. Format")

First, the code is as follows

Dim Filesavename

Filesavename = Application.getsaveasfilename (filefilter:= "Text Files (*.txt), *.txt")

If filesavename <> False Then

MsgBox "Save as" & Filesavename

End If

Second, the title of the specified dialog box

Dim fname as String

Workbooks.Open filename:=2099 results. xls

ActiveSheet.Range (A1). Value = Save

FName = Application.getsaveasfilename (_

Initialfilename:= score saved. xls, _

title:= here is the title text)

If fname <> False Then

ActiveWorkbook.SaveAs Filename:=fname

End If

Knowledge Development:

Application.getsaveasfilename method: Simple is to show the Save As dialog box, user-friendly input file name to save

Grammar:

Expression. Getsaveasfilename (InitialFileName, FileFilter, FilterIndex, Title, ButtonText)

expression Required. The expression returns the type object of the application

InitialFileName variant type, optional. Specifies the initial filename

FileFilter variant type, optional. A string that specifies the file filter criteria, such as: "Text file, *.txt"

FilterIndex Variant type, optional. Specifies the index number of the default file filter criteria, ranging from 1 to the number of filter criteria specified by FileFilter

Title Variant type, optional. Specify a dialog box title

ButtonText Variant type, optional. For Macintosh only

When using, please note the following:

1. If you omit the initialfilename parameter, Microsoft Excel takes the name of the active workbook as the initial file name

2. If the FileFilter parameter is omitted, the default parameter value is "All Files (*.*), *.*"

3. If you omit the FilterIndex parameter, or if the value is greater than the number of available filters, the first file filter condition is used

4. If you omit the title argument, the default caption is used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.