VBA to File SaveAs

Zaigham

Board Regular
Joined
Dec 22, 2010
Messages
159
Office Version
  1. 2021
Platform
  1. Windows
  2. Mobile
Hi,
I need a VBA to save my excel files with a different name.

Thanks in advance

Zaigham
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,
I need a VBA to save my excel files with a different name.

Thanks in advance

Zaigham

If you are using Excel 2003 or earlier then:
File menu > Save As....

If Excel 2007/2010 then click on the Office button (very top left corner). Then click "Save As".
 
Upvote 0
I don't really see why you need a VBA solution for something so simple. But since you asked:

Code:
Sub FileSaveAs()
'
'  Make sure you change the value in between the quotes
'  to the appropriate path where your workbook will be saved.
'
    ChDir "C:\folder1"
    ActiveWorkbook.SaveAs Filename:="C:\folder1\name of new file.xlsx", _
        FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub
 
Upvote 0
Burrgogi,

Thank you for compliments. But I need a macro which interrupt for input a new name each time. Hope now I have explained more clearly.

Regards,
Zaigham
 
Upvote 0
Try this

Code:
Sub SaveMe()
Dim fName As Variant
fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Save As")
If fNameAndPath = False Then Exit Sub
ActiveWorkbook.SaveAs Filename:=fName
End Sub
 
Upvote 0
Thank you very much Peter.:)

Regards,
Zaigham
 
Upvote 0
Hi Peter,

After running the macro, SaveAs dialog appears with "Blank" file name and Save as type: = "Excel Files". But there is something missing as new file name doesn't appears on title bar by changing the current filename nor found in folder where it was saved even not found with windows search utility.:confused:
Hope you will detect the error.
Regards,
Zaigham
 
Upvote 0
Sorry, a small error. Tested and working

Code:
Sub SaveMe()
Dim fName As Variant
fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Save As")
If fName = False Then Exit Sub
ActiveWorkbook.SaveAs fileName:=fName
End Sub

If you are using Excel 2007 or later you might need a small tweak. Let me know.
 
Upvote 0
I am using Excel 2010 at Home and 2003 at office.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top