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
 
Try

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
If CInt(Application.Version) < 12 Then
    ActiveWorkbook.SaveAs Filename:=fName
Else
    ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=52
End If
End Sub
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Dear Peter Sir,

First "error removed macro" works fine. Second one also works fine. However, when I used it on a macro enabled worksheet in Excel 2010 it saved it in Excel worksheet 1997-2003.

Bundle of thanks for devotion and your valuable work which works fine.:bow::bow::bow:

Sincerely,
Zaigham
 
Upvote 0
Maybe this

Code:
Sub SaveMe()
Dim fName As Variant, i As Long
fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Save As")
If fName = False Then Exit Sub
If CInt(Application.Version) < 12 Then
    ActiveWorkbook.SaveAs Filename:=fName
Else
    i = InStrRev(fName, ".")
    fName = Left(fName, i) & "xlsm"
    ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=52
End If
End Sub
 
Upvote 0
Dear Sir,

This macro works fine as saves file in its original version.

Thanks a lot.

Zaigham
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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