Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default BeforeClose vs Auto_Close

I have a nagging issue. I am trying to run a BeforeClose sub but it
just won't go. However, if I replace it with the Auto_Close sub then it
works fine. The code is simple:

private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "close macro is working"
end sub

With the above code I do not see my message box when I close my
workbook. It just closes.

private sub auto_close ()
MsgBox "close macro is working"
end sub

With the above code I get my messagebox (and the useful bits of the
code which I haven't pasted in here). I read something about the need
for events to be enabled, so I ran a macro to enable events
(Application.EnableEvents = True), but to no avail.

It's not a big issue because the Auto_Close does what I need, but as a
fickle follower of fashion I feel out of date. I've read that
Auto_Close is soooooo last centuary ;-). What could I be doing wrong
that stops the beforeclose working but lets auto_close do its job?

regards Ben

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default BeforeClose vs Auto_Close

Hi,
Auto_Close is soooooo last centuary ;-).


correct :)

you have to call another macro in the beforeclose-event like

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Run ("test")
End Sub

BTW: Application.Run ("test") is also a kind medieval ages stuff ;)

arno

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default BeforeClose vs Auto_Close

I have never had to do that. Certainly not for the code the OP showed.

--
Regards,
Tom Ogilvy

"arno" wrote in message
...
Hi,
Auto_Close is soooooo last centuary ;-).


correct :)

you have to call another macro in the beforeclose-event like

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Run ("test")
End Sub

BTW: Application.Run ("test") is also a kind medieval ages stuff ;)

arno



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default BeforeClose vs Auto_Close

Hi Tom,
I have never had to do that. Certainly not for the code the OP
showed.


I remember that I could not make some larger code (subroutines etc etc)
work in the open-event, but it worked when i called it as I described.
I do not know why but then it worked.

arno

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default BeforeClose vs Auto_Close

"arno" wrote in message
...

you have to call another macro in the beforeclose-event like

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Run ("test")
End Sub


Inaccurate in two respects. You don't have to call a macro, you can embed
the code in the event procedure. And you don't need application run, you
could just use
Test
or
Call Test.

Application run is required to run a macro in an other workbook.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default BeforeClose vs Auto_Close

Roedd <<Bob Phillips wedi ysgrifennu:


Inaccurate in two respects.


Inaccurate in three respects in total. Application.Run was never available
in stand-alone VB. However, it was added to VB.NET, so it's very much 'this
century'.

--
Rob

http://www.asta51.dsl.pipex.com/webcam/

This message is copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default BeforeClose vs Auto_Close


"Robert Bruce" <rob@analytical-dynamicsdotcodotukay wrote in message
...

Inaccurate in three respects in total. Application.Run was never available
in stand-alone VB. However, it was added to VB.NET, so it's very much

'this
century'.


<G


PS Is that Gaelic?


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default BeforeClose vs Auto_Close

Roedd <<Bob Phillips wedi ysgrifennu:

PS Is that Gaelic?


Very close. It's Welsh, the language of Heaven:
http://www.bbc.co.uk/wales/storyofwelsh/

--
Rob

http://www.asta51.dsl.pipex.com/webcam/

This message is copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default BeforeClose vs Auto_Close

Ben, do you have the beforeclose code in the thisworkbook module?
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

wrote in message
ups.com...
I have a nagging issue. I am trying to run a BeforeClose sub but it
just won't go. However, if I replace it with the Auto_Close sub then it
works fine. The code is simple:

private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "close macro is working"
end sub

With the above code I do not see my message box when I close my
workbook. It just closes.

private sub auto_close ()
MsgBox "close macro is working"
end sub

With the above code I get my messagebox (and the useful bits of the
code which I haven't pasted in here). I read something about the need
for events to be enabled, so I ran a macro to enable events
(Application.EnableEvents = True), but to no avail.

It's not a big issue because the Auto_Close does what I need, but as a
fickle follower of fashion I feel out of date. I've read that
Auto_Close is soooooo last centuary ;-). What could I be doing wrong
that stops the beforeclose working but lets auto_close do its job?

regards Ben



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default BeforeClose vs Auto_Close

is the BeforeClose sub in the ThisWorkbook module. If not, this might be
the problem.

--
Regards,
Tom Ogilvy


wrote in message
ups.com...
I have a nagging issue. I am trying to run a BeforeClose sub but it
just won't go. However, if I replace it with the Auto_Close sub then it
works fine. The code is simple:

private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "close macro is working"
end sub

With the above code I do not see my message box when I close my
workbook. It just closes.

private sub auto_close ()
MsgBox "close macro is working"
end sub

With the above code I get my messagebox (and the useful bits of the
code which I haven't pasted in here). I read something about the need
for events to be enabled, so I ran a macro to enable events
(Application.EnableEvents = True), but to no avail.

It's not a big issue because the Auto_Close does what I need, but as a
fickle follower of fashion I feel out of date. I've read that
Auto_Close is soooooo last centuary ;-). What could I be doing wrong
that stops the beforeclose working but lets auto_close do its job?

regards Ben





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default BeforeClose vs Auto_Close

Tom, Paul,

I did not have the sub in the thisworkbook module, so I cut and pasted
it in. Still no joy though.

Ben

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default BeforeClose vs Auto_Close

Best to select it from the dropdowns in the top of the module (clear the
module first) and let the declaration be entered by excel.

then insert your

msgbox "In Workbook_BeforeClose"

between the prototype.

That always works for me.

Assumes you haven't disabled events or disabled macros.

--
Regards,
Tom Ogilvy


wrote in message
ups.com...
Tom, Paul,

I did not have the sub in the thisworkbook module, so I cut and pasted
it in. Still no joy though.

Ben



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default BeforeClose vs Auto_Close

Bingo!

Thanks a bunch, Tom. That was going to keep me up all night.

Ben

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default BeforeClose vs Auto_Close

On 2 Jun 2005 07:53:44 -0700, wrote...

[Workbook_BeforeClose, won't fire]
With the above code I do not see my message box when I close my
workbook.



If you've got Excel 2000 but not SR-1 it won't fire. You had to use a
sub named Auto_Close.

Additional info: Event Procedures must be placed in the
module for the object that they work with. E.g., Workbook_BeforeClose
must be placed in the ThisWorkbook module, and the Worksheet_ events
must be placed in the Sheet modules.

See also:
http://tinyurl.com/eysuf

--
Met vriendelijke groeten / Mit freundlichen Grüßen / With kind
regards/Avec mes meilleures salutations
BBert

April 20, 1986
Celtics (135) - Bulls (131)
Larry Bird: "God disguised as Michael Jordan"
  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default BeforeClose vs Auto_Close

Just to point out, that that was a problem only for Addins as I recall.

and it appears he got it working.

--
Regards,
Tom Ogilvy

"BBert" wrote in message
e.nl...
On 2 Jun 2005 07:53:44 -0700, wrote...

[Workbook_BeforeClose, won't fire]
With the above code I do not see my message box when I close my
workbook.



If you've got Excel 2000 but not SR-1 it won't fire. You had to use a
sub named Auto_Close.

Additional info: Event Procedures must be placed in the
module for the object that they work with. E.g., Workbook_BeforeClose
must be placed in the ThisWorkbook module, and the Worksheet_ events
must be placed in the Sheet modules.

See also:
http://tinyurl.com/eysuf

--
Met vriendelijke groeten / Mit freundlichen Grüßen / With kind
regards/Avec mes meilleures salutations
BBert

April 20, 1986
Celtics (135) - Bulls (131)
Larry Bird: "God disguised as Michael Jordan"





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
question about Auto_Close and WorkbookBeforeClose Brian Murphy Excel Programming 8 October 9th 04 08:08 PM
Question about auto_close Neil[_20_] Excel Programming 3 July 7th 04 09:24 PM
BeforeClose, Auto_Close, and ActiveX Server Don Wiss Excel Programming 0 November 21st 03 12:21 AM
Auto_Close() needs help Phil Hageman[_3_] Excel Programming 3 November 19th 03 05:56 PM
Auto_Close Luc Benninger Excel Programming 2 October 14th 03 12:34 PM


All times are GMT +1. The time now is 01:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"