tags:

views:

208

answers:

4

I am executing code on the WindowSelectionChange event in Microsoft Word. How come when I open another document, that does not have this macro referenced in it, the code is still being called on WindowSelectionChange. I do not have the macro stored in the default template, it is stored in a template not referenced by my other word documents.

Is there a way to limit this event to the document that has the VBA code in it?

A: 

Is it possible that you made the macro in the default template instead of in the specific document?

EBGreen
A: 

Yes, in the macro editor, make sure your code is in the project for your document and the the one called "Normal".

Maudite
A: 

The macro events only fire unwantedly if the document that they are supposed to fire in is open at the same time. The project is stored in my own .dot file, not the default template.

Is this just the nature of binding events in word? It effects all open documents. Any ideas?

joe
+1  A: 

I believe the WindowSelectionChange event is called at the application level, right? So basically I think the way to fix this is to modify the code in the WindowSelectionChange so that it only executes if ActiveDocument = ThisDocument. ThisDocument is the document where your code is stored, so you can make it so the code executes only when ThisDocument is the active document in Word.

Hope that helps...

Jon Fournier