Closing methods

  • Thread starter Thread starter kurt
  • Start date Start date
K

kurt

He All

I have a funny problem when closing files from a macro outside the file
I want to close. That I cant imagine what is happend.

I have in my Personal.xls a macro called Close_files.

When I execute this macro the function is to close the workbook called
test.xls.

In test.xls there is a macro - Sub Workbook_BeforeClose(Cancel As
Boolean)-
in this there is an expression - Sheets("Base informations").Select


When I run macro Close_files; Sheets("Base informations").Select --
is not selected
The rest of the
code is executed as normal


When I close test.xls; Sheets("Base informations").Select - is
selected
The rest of the code is
executed as normal

Please Help

regards
Kurt
 
kurt said:
He All

I have a funny problem when closing files from a macro outside the file
I want to close. That I cant imagine what is happend.

I have in my Personal.xls a macro called Close_files.

When I execute this macro the function is to close the workbook called
test.xls.

In test.xls there is a macro - Sub Workbook_BeforeClose(Cancel As
Boolean)-
in this there is an expression - Sheets("Base informations").Select


When I run macro Close_files; Sheets("Base informations").Select --
is not selected
The rest of the
code is executed as normal


When I close test.xls; Sheets("Base informations").Select - is
selected
The rest of the code is
executed as normal

Please Help

regards
Kurt
 
Hi
I don't think event code fires when you open or close using CODE, but
then your code executing after the select is odd?
regards
Paul
 
Hi

The code is running smoothly in the test.xls file when I close it
directly

When I close it from the macro in Personal.xls I can follow the codes
execution, but it do not execute this step ;
That means that if I want to update something in the ("Gase
Information") sheet it will not be updated there byt on the sheet there
is active and this is odd..

regards

Kurt


(e-mail address removed) skrev:
 
It is probably trying to close a worksheet in the workbook that is running
the macro. Change it to

ThisWorkbook.Sheets("Base informations").Select


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Hi
I thought you could not fire an Auto_Open macro, say, if you opened the
file with code. Is that not the case? (I'm too lazy to go check
myself!)
regards
Paul
 
What has Auto_Open got to do with anything here? He is using BeforeClose
which does run from code quite happily.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
See RunAutoMacros in VBA's help.

You have to explicitly stop the workbook_open event from firing and you have to
explicitly run the auto_open (well, if you want).
 
Back
Top