ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA - Save with New Filename (https://www.excelbanter.com/excel-programming/375034-vba-save-new-filename.html)

Louise

VBA - Save with New Filename
 
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,

Kevin B

VBA - Save with New Filename
 
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.
--
Kevin Backmann


"Louise" wrote:

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,


Jim Rech

VBA - Save with New Filename
 
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

--
Jim
"Kevin B" wrote in message
...
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.
--
Kevin Backmann


"Louise" wrote:

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,





All times are GMT +1. The time now is 02:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com