NOTE: If you use the full path for the file name, Microsoft Excel will know exactly where to save the file. If the path is not given, Microsoft Excel will save the file to the currently active directory or folder.
Sample Macro 1Save the active workbook with a variable to a specified path. To do this, use the following macro:
Dim MyFile As String
MyFile = ActiveWorkbook.Name
' Do not display the message about overwriting the existing file.
Application.DisplayAlerts = False
' Save the active workbook with the name of the
' active workbook. Save it on the E drive to a folder called
' "User" with a subfolder called "JoeDoe."
ActiveWorkbook.SaveAs Filename:="E:\User\JoeDoe\" & MyFile
' Close the workbook by using the following.
Sample Macro 2Use a file name stored in a cell and save the file to the network server. To do this, use the following macro:
Dim SaveName As String
SaveName = ActiveSheet.Range("A1").Text
ActiveWorkbook.SaveAs Filename:="E:\User\JoeDoe\" & _
SaveName & ".xls"
Article ID: 213641 - Last Review: Jan 23, 2007 - Revision: 1