Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 217
Default 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,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default 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,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default 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,



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
Doing a save with a variable filename? nbaj2k[_23_] Excel Programming 1 August 2nd 06 01:50 PM
save as different filename Tom Excel Programming 3 May 4th 05 03:41 AM
Save Filename Peter Excel Programming 3 February 4th 05 01:15 PM
save as filename Geo Siggy[_14_] Excel Programming 3 April 6th 04 01:26 PM


All times are GMT +1. The time now is 06:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"