Changed the code to
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wkbk1, wkbk2 As Workbook, wksheet1, wksheet2 As Worksheet, intIndex As Integer
'set the source workbook
Set wkbk1 = Application.Workbooks("Trial1.xlsm")
'set the source worksheet
..................
And now it works when I shut Excel down