DefaultExt

Returns or sets the extension that Windows adds to a file name that the user types without one.

Syntax: object.DefaultExt [ = string ]

object
required An object expression that evaluates to a cDialog.
string
A String, an extension written without a period, such as txt. The default is an empty string.

Remarks

ShowOpen and ShowSave pass the text as the lpstrDefExt member of OPENFILENAME. ShowBrowseForFolder ignores it.

Windows appends the extension to a name that the user types without one. Write the extension without a period. The class does not change the text, and does not take an extension from the selected pair of Filter.

In the Save As dialog, with the user typing out:

DefaultExt ShowSave returns
txt <dir>\out.txt
.txt <dir>\out..txt
An empty string <dir>\out

<dir> is the folder of the dialog. A period in DefaultExt is kept, and gives a name with two periods. An empty DefaultExt appends nothing.

Example

Dim dlg As New cDialog
Debug.Print "[" & dlg.DefaultExt & "]"   ' []

dlg.DefaultExt = "txt"
Debug.Print dlg.DefaultExt               ' txt

This example shows the Save As dialog and adds .txt to a name typed without an extension.

Dim dlg As New cDialog
dlg.DefaultExt = "txt"
dlg.SetCommonFilters
Debug.Print dlg.ShowSave()

See Also

  • Filter property – the file-type list, which does not set the extension
  • ShowSave method – shows the Save As dialog
  • ShowOpen method – shows the Open dialog
  • cDialog class – overview