Hello, I am new to vba coding and also to the forum. I am having trouble coding an excel file to automatically change the file name based off of what is already saved in the directory. For example: first file would save as 1.xlsm and the second 2.xlsm……etc. I have the following code and cannot figure out why it will not work:
DIM na As Long
na = 1
sfilename = "V:\Finance\" & na
Do
If Dir(sfilename) <> "" Then
'"V:\Finance\" & na Then
na = na + 1
Let sfilename = "V:\Finance" & na
Else
End If
Loop Until Dir(sfilename) = ""
ActiveWorkbook.SaveAs Filename:=sfilename
Anyone have any ideas? Thanks, Tom
Moderator Edit:
Welcome to the forum, Tom Brennan.
Please notice that code tags have been added to your post. The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
Thanks.
Bookmarks