VBA Save a copy of file with similar filename

LookingForHazyDays

New Member
Joined
Jan 26, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I have an Excel file which currently uses vba to delete stuff and then save what's left as a new file with the new filename written into the macro. Like this:

ActiveWorkbook.SaveAs Filename:="x:\Folder Name\Client1_Client2_ClientCopy.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.DisplayAlerts = False
End Sub


Instead, what want the vba to do is save the file as the current file name with "Client Copy" on the end.
How do I do this please?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi & welcome to MrExcel.
How about
VBA Code:
With ActiveWorkbook
   .SaveAs FileName:="x:\Folder Name\" & Replace(.Name, ".xlsm", "") & "_ClientCopy.xlsm", _
   FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End With
 
Upvote 0
Welcome to the Board!

Try something like this:
VBA Code:
    Dim fname As String
    fname = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5) & "Client Copy.xlsm"
    
    ActiveWorkbook.SaveAs Filename:="x:\Folder Name\" & fname, _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        Application.DisplayAlerts = False
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
With ActiveWorkbook
   .SaveAs FileName:="x:\Folder Name\" & Replace(.Name, ".xlsm", "") & "_ClientCopy.xlsm", _
   FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End With
Super, works a treat, thanks very much!
 
Upvote 0
Welcome to the Board!

Try something like this:
VBA Code:
    Dim fname As String
    fname = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5) & "Client Copy.xlsm"
   
    ActiveWorkbook.SaveAs Filename:="x:\Folder Name\" & fname, _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        Application.DisplayAlerts = False
Super too, also works, thanks very much!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,825
Members
449,096
Latest member
Erald

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