Hello forum members,
I need your help finding a solution to the following problem:
I have an excel 2010 spreadsheet that creates a new sheet when it opens by saving itself with a different name... in other words, the original file is tx master.xlsm and after it's double-clicked the file saves as tx and that day's date (example: tx 01-07-2013.xlsm). I used the following to accomplish the task:
myFolder = "C:\users\pete\desktop\"
myFile = myFolder & "tx" & " " & Format(Date, "mm-dd-yyyy") & ".xlsm"
If Not IsFileExists(myFile) Then
ActiveWorkbook.SaveAs "C:\users\pete\desktop\" & "tx" & " " & Format(Date, "mm-dd-yyyy") & ".xlsm", FileFormat:=52
End If
The first problem came when the user had the second sheet opened and tried to double-click the original sheet; the user ended up writing data to the original sheet instead of the second one. I tried solving this issue by implementing a security check to see if the second file existed, and if so, to let the user know that he needed to use the correct file; after the user clicked "Ok" the original file closed and that was that.
If IsFileExists(myFile) Then
MsgBox "Today's file has been created already." & vbNewLine & "Please use that file instead of this one.", vbExclamation + vbOKOnly, "File in Use"
ActiveWorkBook.Close SaveChanges:=False
End If
But then, another problem arose: if the user closed and then tried to reopen the second file he got the same message intended for the original file; so the user got stuck in a loop in which the file doesn't open. How can this problem be avoided? I need the original file to create the second file; while keeping the user from trying to open the original file if the second file has been created; and letting the user close the second file and open it without having to deal with the messages meant to limit the use of the original file.
Any help would be greatly appreciated!!
Bookmarks