Run mackro before close

  • Thread starter Thread starter lud1
  • Start date Start date
L

lud1

Hi All,
I have read some posts but still the problem exists.
I create form with macros what transfer data from the form to the tabl
in second sheet. The file is saved with tha same name, saves as .xl
always with new name and as .txt with the same name. I would like t
create a macro what enable my macro (transfering data and saving a
above), when someone clicks on save or close button.
I have already tried to use
Sub Workbook_BeforeClose ()
Application.run "A.xls!X"
End Sub

and similarly

for BeforeSave and it does't work. I don't know why ?
Moreover in one of the posts I have found that usin
Workbook_BeforeClose it worked as Cancel As Boolean. What does it mea
in simply words ?

Thnaks in advance for your simple suggestions.

lud
 
Where have you put this code? Is it in the thisworkbook code module.

Also noted that your code only says sub not private sub.

It might be worth checking that as I have just tested the before save
and close events on my worksheet and it worked just fine.
 
1. The events you use must go into the special ThisWorkBook module foun
in VB Editor View/Project Explorer then doubleclick ThisWorkBook.

2. Putting the line
Cancel = True
into Before_Close stops the event happening. i.e. the workbook does no
close. We can use this to check for Save or correctly entered dat
before allowing the workbook to be closed
 
chandlm said:
*Where have you put this code? Is it in the thisworkbook code module.
Yes a a separate macro named Workbook_BeforeClose
Is it correct ?

Also noted that your code only says sub not private sub. All macros I
created by showing what must be done are as sub not private sub and
they work fine. I ried with private sub also - no success.

It might be worth checking that as I have just tested the before save
and close events on my worksheet and it worked just fine. *
 
Back
Top