run macro on close

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
 
G

GS

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

See the reply in your other post.
 
G

Gord Dibben

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
 
A

Auric__

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
 
G

Gord Dibben

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top