JKwan
03-28-2011, 12:53 PM
Wondering if someone may know what is not quite right with the code....
Basicall, if someone hit the SAVE button, I want to override the built in SAVE function with my own, so it gives a versioning of filenames. If I run it as is (traced it and all lines get executed), I don't get my file, nothing, very strange. However, if I attach the code to a button, I get exactly the outcome that I anticipated.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
SaveWithVersioning
End Sub
sub SaveWithVersioning
Dim sFileName As String
Dim sCurrentName As String
sCurrentName = Worksheets("SIMOPS").Cells(2, "I")
sFileName = CleanFileName(sCurrentName)
sFileName = ThisWorkbook.Path & "\" & sFileName & "-" & Format(Now, "mmm-dd-yyyy") & ".xls"
If DiskFileExists(sFileName) Then
ThisWorkbook.Save
Else
ThisWorkbook.SaveAs sFileName
End If
end sub
Basicall, if someone hit the SAVE button, I want to override the built in SAVE function with my own, so it gives a versioning of filenames. If I run it as is (traced it and all lines get executed), I don't get my file, nothing, very strange. However, if I attach the code to a button, I get exactly the outcome that I anticipated.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
SaveWithVersioning
End Sub
sub SaveWithVersioning
Dim sFileName As String
Dim sCurrentName As String
sCurrentName = Worksheets("SIMOPS").Cells(2, "I")
sFileName = CleanFileName(sCurrentName)
sFileName = ThisWorkbook.Path & "\" & sFileName & "-" & Format(Now, "mmm-dd-yyyy") & ".xls"
If DiskFileExists(sFileName) Then
ThisWorkbook.Save
Else
ThisWorkbook.SaveAs sFileName
End If
end sub