Incrementing File Name when using save as a macro

marav08

New Member
Joined
Sep 22, 2017
Messages
6
[h=2]Hi,[/h]

please do correct if violate some rules. I have a workbook that needs to be saved everytime there is a new name that is selected and if ever that the same name will be save the file name will increment. The filename I choose is the value of cells. Name - Date - Line of business. so for eg. My first file is Ryan-07-21-2017-Tech. then I will be saving a file again with the same criteria it should now be Ryan-07-21-2017-Techv2. I already have a code but it seems that everytime I will be saving the same file name my excel file is not responding anymore and then is there a possible way as well the each time I save as a file my main workbook will not be closed? Thanks.
Below are my codes.

Code:
Sub Button38_Click()
Dim i As Long
Dim Path As String
Dim FileName1 As String
Dim FileName2 As String
Dim nameDate As String
Dim fn As String
Dim check As String
Dim ok As Boolean

FileName1 = Range("B4")
FileName2 = Range("B6")
nameDate = Format(Date, "dd.mm.yyyy")
Path = "\\10.80.2.4\Shared Folder$\Acurus Folder Redirection\virgilio.beltran\Desktop\New folder"

fn = Path & FileName1 & "-" & FileName2 & "-" & nameDate & ".xlsm"
check = Dir(fn)
ok = (check = "")

Do Until ok
i = i + 1
fn = Path & FileName1 & "-" & FileName2 & "-" & nameDate & ".xlsm"
check = Dir(fn)
ok = (check = "")
Loop

ThisWorkbook.SaveAs fn



'ActiveWorkbook.SaveAs Filename:=Path & FileName1 & "-" & FileName2 & "-" & nameDate & ".xlsm", FileFormat:=xlNormal


End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules. Be sure to follow & read the link at the end of the rule too!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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