GetSaveAsFilename default folder

excel, vba

Solution

The `FileDialog` object offers way more flexibility than `GetSaveAsFilename` (and its sibling `GetOpenFilename`). Example:

Dim tuneSaver As FileDialog
Set tuneSaver = Application.FileDialog(msoFileDialogSaveAs)

With tuneSaver
    .Title = "Save this tune as..."
    .InitialFileName = "C:\MyDocuments\Music\"
    ' Set other properties here...
    .Show
End With

Note that an `.InitialFileName` longer than 256 characters will cause a run-time error.

See VBA help on `FileDialog`. It has quite a few useful properties, including e.g. `AllowMultiSelect` (though admittedly this one is irrelevant when saving).

Problem

I am using `GetSaveAsFilename` in VBA for Excel. Is there any way to give this a default folder to open up to? For example, I always want it to start at `C:\MyDocuments\Music` when it is called.

Original source