Need to add Suffix in specific file name

Aswinraj

Board Regular
Joined
Dec 10, 2015
Messages
65
Hello All,

I have a Macro, where it will open Previous file and Refresh the data. After Refresh it will Save the file.
Now I want to add "_Refreshed" in the File name without changing existing file name.

Example: File Name Before Macro Refresh "Markets_ 29 May'20.xlsb" and If i am doing refresh today then it should save as "Markets_29May'20_Refreshed.xlsb"

Can anyone help please.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I don't know if this is exactly what you wanted, but it does work:

VBA Code:
Sub SaveRefreshed(wbTarget As Workbook)

    Dim strFilename         As String
    Dim strNewFilename      As String
    Dim strExtension        As String
    Dim strTemp             As String
    Dim lngTemp             As Long
    
    strFilename = wbTarget.FullName
    lngTemp = InStrRev(strFilename, ".")
    strTemp = Left(strFilename, lngTemp - 1) & "_Refreshed."
    strExtension = Right(strFilename, Len(strFilename) - lngTemp)
    
    strNewFilename = strTemp & strExtension
    wbTarget.SaveAs strNewFilename
   ' If you want to save a copy, then replace the line with:
    'wbTarget.SaveCopyAs strNewFilename
         
End Sub

It takes a Workbook as an argument, and then adds the suffix. In the code above, it will save that workbook with the new filename. If, however, you want to save a copy of the workbook, then you just need to replace the code with the one in the comments.

Example usage:

SaveRefreshed Thisworkbook SaveRefreshed Application.Activeworkbook SaveRefreshed Application.Workbooks("Markets_ 29 May20.xlsb")
 
Upvote 0
@Dan_W Thanks for your code but i am unable to call this code. May i know how to incorporate this code into any existing code.
 
Upvote 0

Forum statistics

Threads
1,223,637
Messages
6,173,488
Members
452,515
Latest member
archcalx

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