Prevent BeforeClose event from running for every open document

  • Thread starter Peter Trägårdh
  • Start date
P

Peter Trägårdh

In my project I subscribe to the BeforeClose event. If I have two or more
documents open with this macro, all the documents gets hit by the event, not
just the one I am closing, no worries there. But what I would like to do is
to only have the document that's closing to run the code in the event. Is
there a way to prevent the other documents from running the code in the
events?

/Peter Tragardh
 
J

JGM

Hi Peter,

Yes, two ideas come to mind:

Customized document properties or Document variables.

Just check for the presence/value of a predefined property or varibale
before running the code.

I prefer the Document variable because it is totally invisible to the user,
so he/she cannot mess with it....

HTH
Cheers!
 
P

Peter Tragardh

Any ideas on how to create a unique value for every document? I can't
hard code it since the macro is in the dot-file. Every doc-file would get
the same value.

And if I create a unique value dynamically for every document, how does
the save event know which value to check for?


JGM said:
Hi Peter,

Yes, two ideas come to mind:

Customized document properties or Document variables.

Just check for the presence/value of a predefined property or varibale
before running the code.

I prefer the Document variable because it is totally invisible to the
user, so he/she cannot mess with it.... [SNIP]
Peter Trägårdh said:
In my project I subscribe to the BeforeClose event. If I have two or
more documents open with this macro, all the documents gets hit by
the event, not
just the one I am closing, no worries there. But what I would like to
do is
to only have the document that's closing to run the code in the
event. Is there a way to prevent the other documents from running the
code in the events?
 
J

JGM

Hi Peter,

Create the value in the Document_New Event.

If you want the BeforeClose to run, create the Document Variable with the
value "YES" for those that need the procedure to run, and the Value "NO" for
the others.
Then you can hard code:
(In Pseudo code)

If Document_Variable("Check_First") = "YES" then run code in
BeforeClose....

HTH
Cheers!

--
_______________________________________
Jean-Guy Marcil
(e-mail address removed)

Peter Tragardh said:
Any ideas on how to create a unique value for every document? I can't
hard code it since the macro is in the dot-file. Every doc-file would get
the same value.

And if I create a unique value dynamically for every document, how does
the save event know which value to check for?


JGM said:
Hi Peter,

Yes, two ideas come to mind:

Customized document properties or Document variables.

Just check for the presence/value of a predefined property or varibale
before running the code.

I prefer the Document variable because it is totally invisible to the
user, so he/she cannot mess with it.... [SNIP]
Peter Trägårdh said:
In my project I subscribe to the BeforeClose event. If I have two or
more documents open with this macro, all the documents gets hit by
the event, not
just the one I am closing, no worries there. But what I would like to
do is
to only have the document that's closing to run the code in the
event. Is there a way to prevent the other documents from running the
code in the events?
 

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