
Originally Posted by
patel
Admin
very interesting code, can you comment it ?
Hi
here you go.
Code:
Sub kTest()
Dim strFName As String
Dim strExtn As String
Dim strPath As String
Dim lngFNum As Long
Dim nmFNum As Name
Const FName = "ivan ivanov"
On Error Resume Next
Set nmFNum = ThisWorkbook.Names("FNum") 'a defined name
On Error GoTo 0
If nmFNum Is Nothing Then 'for the first time we have to add the name
Set nmFNum = ThisWorkbook.Names.Add("FNum", 1, 0) 'add the defined name for the first time (0 - visible=false)
lngFNum = 1
Else
lngFNum = Evaluate("FNum") + 1 'get the previous number + 1
nmFNum.RefersTo = lngFNum 'assign the new number
End If
strFName = ThisWorkbook.FullName
strExtn = Mid$(strFName, InStrRev(strFName, "."))
strPath = Left$(strFName, InStrRev(strFName, "\"))
ThisWorkbook.SaveCopyAs strPath & FName & lngFNum & strExtn
End Sub
Bookmarks