I've never worked with an xlam, so this is just some cut and pastes from the help file, your post, and my own Personal.xls. It probably needs a reference to the MS VBA Extensibility dll.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Application.VBE.VBProjects(1).Saved Then _
Me.SaveCopyAs ("C:\Users\SebastionH\AppData\Roaming\Microsoft\AddIns\Archives\" & Me.Name & " - " & CStr(CDbl(Now)) & ".xlam")
End Sub
The CStr(CDbl(Now)) just puts a unique (to the millisecond) TimeStamp String in the saved File Name
If you manually save the file, that code will not run. In my Personal, I test and Save BeforeClose and SaveCopyAs when Saveing