MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Let macro perform an action on 'excel close'


Posted by Remi on January 31, 2002 1:21 AM

hey, I`m building a macro which has to copie a few cell to another .xls file. This copying however, must take place when the first file is being closed.

How do I get this done? My approach would be: record a macro for the parts that are done within the first file. Then get into this macro and edit it. But it is virtually impossible to search for what I`m looking for via a keyword.

Hope someone can help me!
tnks.

Remi
Holland.

Posted by Jim on January 31, 2002 5:35 AM

Record the macro and place it into the "ThisWorkbook" object under sub Workbook_BeforeClose


record a macro for the parts that are done within the first file. Then get into this macro and edit it. But it is virtually impossible to search for what I`m looking for via a keyword.

Posted by Carl B on January 31, 2002 7:22 AM

In VBA under Workbook insert this
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Workbook("Filename and path here").Worksheets("name Of Sheet here") = ActiveWorkbook.Worksheets("name of sheet to copy from").Range("cell range here")
End Sub record a macro for the parts that are done within the first file. Then get into this macro and edit it. But it is virtually impossible to search for what I`m looking for via a keyword.

Posted by Remi on February 01, 2002 12:23 AM

THANK YOU ALL! Gonne use your tips.