[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.
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