InitialDir
Returns or sets the folder in which the Open and Save As dialogs start.
Syntax: object.InitialDir [ = string ]
- object
- required An object expression that evaluates to a cDialog.
- string
- A String, the path of a folder. The default is an empty string.
Remarks
ShowOpen and ShowSave pass the text as the lpstrInitialDir member of OPENFILENAME. The class does not check that the folder exists. Windows chooses the starting folder in the order that the documentation of lpstrInitialDir gives.
ShowBrowseForFolder does not use InitialDir. Its dialog opens with the folder of the user’s profile selected, whatever InitialDir holds.
Note
A ShowBrowseForFolder that the user confirms replaces InitialDir with the folder it returns, a path typed into the edit box of the dialog included. A ShowOpen or ShowSave after it is given that folder as its starting folder. Set InitialDir again if that is not wanted.
VB6’s CommonDialog control calls this property InitDir.
Example
Dim dlg As New cDialog
Debug.Print "[" & dlg.InitialDir & "]" ' []
dlg.InitialDir = "C:\Reports"
Debug.Print dlg.InitialDir ' C:\Reports
This example starts the Save As dialog in a given folder.
Dim dlg As New cDialog
dlg.InitialDir = "C:\Reports"
dlg.DefaultExt = "txt"
Debug.Print dlg.ShowSave()
See Also
- FileName property – the file name shown when the dialog opens
- ShowOpen method – shows the Open dialog
- ShowSave method – shows the Save As dialog
- ShowBrowseForFolder method – writes the chosen folder to InitialDir
- cDialog class – overview