Private Sub Workbook_BeforeClose(Cancel As Boolean)
Closedby = Application.UserName
DateClosed = Now()
Application.DisplayAlerts = False
mypath = ActiveWorkbook.FullName
mypath2 = Left(ActiveWorkbook.FullName, Len(ActiveWorkbook.FullName) - Len(ActiveWorkbook.Name))
On Error GoTo CantOpen:
Workbooks.Open mypath2 & "Change Log.xlsx", ReadOnly:=False
Set wb = ActiveWorkbook
cpyrng4 = wb.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
wb.Sheets("Sheet1").Range("A" & cpyrng4).Value = "Closed File"
wb.Sheets("Sheet1").Range("B" & cpyrng4).Value = Closedby
wb.Sheets("Sheet1").Range("C" & cpyrng4).Value = DateClosed
wb.Save
wb.Close
Application.DisplayAlerts = True
Set wb = Nothing
Exit Sub
CantOpen:
Workbooks.Add
ActiveWorkbook.SaveAs mypath2 & "Change Log.xlsx", FileFormat:=51
Resume Next
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Saveby = Application.UserName
DateSave = Now()
Application.DisplayAlerts = False
mypath = ActiveWorkbook.FullName
mypath2 = Left(ActiveWorkbook.FullName, Len(ActiveWorkbook.FullName) - Len(ActiveWorkbook.Name))
On Error GoTo CantOpen:
Workbooks.Open mypath2 & "Change Log.xlsx", ReadOnly:=False
Set wb = ActiveWorkbook
cpyrng3 = wb.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
wb.Sheets("Sheet1").Range("A" & cpyrng3).Value = "Save File"
wb.Sheets("Sheet1").Range("B" & cpyrng3).Value = Saveby
wb.Sheets("Sheet1").Range("C" & cpyrng3).Value = DateSave
wb.Save
wb.Close
Application.DisplayAlerts = True
Set wb = Nothing
Exit Sub
CantOpen:
Workbooks.Add
ActiveWorkbook.SaveAs mypath2 & "Change Log.xlsx", FileFormat:=51
Resume Next
End Sub
Private Sub Workbook_Open()
Openby = Application.UserName
DateOpen = Now()
Application.DisplayAlerts = False
mypath = ActiveWorkbook.FullName
mypath2 = Left(ActiveWorkbook.FullName, Len(ActiveWorkbook.FullName) - Len(ActiveWorkbook.Name))
On Error GoTo CantOpen:
Workbooks.Open mypath2 & "Change Log.xlsx", ReadOnly:=False
Set wb = ActiveWorkbook
cpyrng2 = wb.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
wb.Sheets("Sheet1").Range("A" & cpyrng2).Value = "Open File"
wb.Sheets("Sheet1").Range("B" & cpyrng2).Value = Openby
wb.Sheets("Sheet1").Range("C" & cpyrng2).Value = DateOpen
wb.Save
wb.Close
Application.DisplayAlerts = True
Set wb = Nothing
Exit Sub
CantOpen:
Workbooks.Add
ActiveWorkbook.SaveAs mypath2 & "Change Log.xlsx", FileFormat:=51
Resume Next
End Sub