Save with new sequence number VBA

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
882
Hi all, i would like to develop the below VBA code, so that when i save the file "Employees Finger" 2nd, 3rd, 4th time, e.t.c to enter a new sequence number at the end of the file. e.g. "Employees Finger1", "Employees Finger2" and so on.....

Tks in advance


ChDir "C:\Users\User\Desktop"
ActiveWorkbook.SaveAs Filename:="C:\Users\User\Desktop\Employees Finger.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi John, i tested and i think it works, but unfortunately i couldn't adapt it in my data. Many thanks for your support.
 
Upvote 0
Code:
Public Sub SaveNext()
    Dim nextFileName As String
    nextFileName = GetNextFileName("C:\Users\User\Desktop\Employees Finger|n|.xlsx")
    ActiveWorkbook.SaveAs fileName:=nextFileName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub


Private Function GetNextFileName(filePath As String) As String

    Dim n As Integer
    
    n = 0
    Do
        n = n + 1
        GetNextFileName = Replace(filePath, "|n|", n)
    Loop Until Dir(GetNextFileName) = vbNullString
    
End Function
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,201
Members
449,214
Latest member
mr_ordinaryboy

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