VBA - Save with New Filename

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have written some code and at the end I want my workbook to be saved with
an altered name, and then close the workbook.

i.e. the macro has finished running on previously saved file named "Test
File 2.xls", i want the end of my macro to call this file "Test File 2 -
altered.xls", and save it in the same location as the original file and then
close the workbook.

Any suggestions?

Thanks,
 
Put the following command line at the end of your macro:

Activeworkbook.SaveAs "Test File 2 - altered"

The xls extension will automatically be added and it will use the current
directory as the save location.
 
and it will use the current directory as the save location.

But she wants to use the workbook's path, which might be different. so
maybe:

Sub a()
Dim PathStr As String
PathStr = ActiveWorkbook.Path
If Right(PathStr, 1) <> "\" Then
PathStr = PathStr & "\"
End If
ActiveWorkbook.SaveAs PathStr & "Test File 2 - altered"
End Sub
 
Back
Top