run macro on close

  • Thread starter Thread starter Fawn Lagimodiere
  • Start date Start date
F

Fawn Lagimodiere

I have a 50 files and I want it to run a macro to copy and paste to new
sheet in the file on closing the document.

Is there a code to run this process.

thanks
 
Please do not repost the same Q (in the same words OR other words)!!!

See the reply in your other post.
 
Your description leaves ambiguity as to what your needs are.

Do you want to loop through each of 50 files, copy something, insert a
new sheet and paste then close, presumably after saving?

Or just need code in each workbook that runs on closing that workbook?



Gord
 
Fawn said:
I have a 50 files and I want it to run a macro to copy and paste to new
sheet in the file on closing the document.

Is there a code to run this process.

As Garry said, the copying problem is already addressed.

To run code when a workbook closes, open the workbook's class in the VBA
editor and add this sub:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'your code here
End Sub
 
Taking your subject heading of "run macro on close" literally.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
code to copy, insert and paste
Thisworkbook.save
End Sub

Entered in Thisworkbook module.


Gord
 
Back
Top