I have the following macro to auto save a workbook:
ActiveWorkbook.SaveAs Filename:=Workbooks(2).Path & "\" & ActiveWorkbook.Name
ActiveWorkbook.Close savechanges:=True
but the problem I have if the destination folder already has file with this name I get a message from Excel saying that this file already exists and whether I want to replace it.
What I need is the following:
- if user selects
Yes, then replace the existing file - if user selects
No(currently I get a runtime error), then it saves it with V2 at the end of the file name, if this exists then V3 and so on - if user selects
Cancel, then they see a message saying Are you sure you want to cancel. If they confirm then it's cancelled, otherwise it returns to the error message.
Or perhaps the code can be edited so that when it saves as it checks if file already exists in folder and if it does, then save it as v2.
Dir$function will be useful to determine if a file exists, and UX-wise I would advise against having too many confirmation pop-ups, they get annoying for the users.Workbooks(2)is dangerous. If they have other workbooks or addins open your code will save something other than what you expect.