I used to know how to do this and now I've forgotten again. I've pasted this code into the "ThisWorkbook" section. What else do I need to do to ensure that the code will automatically run when I open the file??
Sub Auto_Open()
Resp = MsgBox("Do you want to save an archived version of template for upserts? Because this sh*t is pretty unstable and could crash at any time.", vbYesNo)
If Resp = vbYes Then
Dim wb As Workbook
'----Saving Part
Dim newFileName As String
Application.DisplayAlerts = False
newFileName = "Template for Upserts Archive" & Format(Now, " MM-DD HHMM") & ".xlsm"
ActiveWorkbook.SaveAs Filename:="M:\My Folder\Karen Postiglioni\JP\Template REPORTS\Tool Archives\\" & newFileName
Workbooks.Open Filename:= _
"M:\My Folder\Karen Postiglioni\JP\Template REPORTS\Template for Upserts.xlsm"
For Each wb In Workbooks
If Left(wb.Name, 28) = "Template for Upserts Archive" Then
wb.Close
End If
Next
Application.DisplayAlerts = True
Windows("Template for Upserts").Activate
Else
msbgox ("That's Kew")
Exit Sub
End If
End Sub
Bookmarks