Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Prefill file name (Save As Dialog) 1

Status
Not open for further replies.

hsp7777

Programmer
Jan 11, 2005
67
US
Greetings,

I am using the following code to display the "Save As" dialog box in Excel. I was wondering, however, if there is a way to "pre-fill" the filename textbox with a name other than "Book1"?

Sub main()
Application.Dialogs(xlDialogSaveAs).Show
End Sub

Thanks in advance!
 
Not tested, but something along the lines of this, maybe:
Code:
    Dim dlgMyDialog As FileDialog
    dlgMyDialog = Application.FileDialog(msoFileDialogSaveAs)
    dlgMyDialog.InitialFileName = "test.xls"
Hope this helps.

[pc2]
 
Take a look at the Application.GetSaveAsFilename method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi hsp7777,

If you have Excel XP (or 2003) you can use the FileDialog as posted by mp9 (but note the second line should say Set dlgMyDialog etc.).

If you have Excel 2000, or 97 (and this also works in later versions) then just add the file name as a parameter ..

[blue]
Code:
Application.Dialogs(xlDialogSaveAs).Show [red]"MyFileName"[/red]
[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top