How to Save As from VBA


Posted by James on August 31, 2001 4:46 AM

I'm hoping this is an easy one. I want to be able to have a macro which will bring up the Save as command window. Basically, is it possible to run the saveas command from VBA with out specifying the name of the file in the code?

Posted by Dax on August 31, 2001 4:53 AM

It is an easy one!

Sub CallUpSaveAs()
Dim sFileName As String
sFileName = Application.GetSaveAsFilename(Title:="Save File As")
If sFileName = "False" Then Exit Sub 'User cancelled
ActiveWorkbook.SaveAs sFileName
End Sub

Hth,
Dax.



Posted by Robb on August 31, 2001 5:01 AM

James

You are able to display a "SaveAs" dialog box into which the user may enter a filename. Howver, this alone does not save the file, it simply returns the path/name by which the user wishes the file to be saved.
If you wish the file to be saved, you must use the FileSaveAs statement. It all goes something like this:

(I will show this as self-contained, but you may use the code anywhere you wish.

Sub SaveMyFile()
Dim myname As String
myname = Application.GetSaveAsFilename
ActiveWorkbook.SaveAs myname
End Sub

Any help?

Regards