disable events in word

N

neoret

I need to disable an event for a short amount of time in my shared addin. I
use c#.

First I can set up how the event is created:

When I run word the connect class starts. In the connect class I add the
presentationBeforeSave eventhandler like this:
((Microsoft.Office.Interop.PowerPoint.Application)applicationObject).DocumentBeforeSave+=
new new
Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler( word.WordDocumentBeforeSave );

I need to catch the save-event for so that I can manage the saving of the
document for the user.

I need to turn this event off in one special case.... In excel I can do
this by saying
theActiveExcelWorkbook.Application.EnableEvents = false; for then setting it
to true after doing what I need to do.

I cannot find this method in word. Do you have a tips for me on how to
handle this?
 
S

Shauna Kelly

Hi neoret

Word (sadly) has no equivalent of Excel's Application.EnableEvents method.

The workaround is generally to create a global or module-wide variable
called, say, bEventsEnabled as a boolean. Wrap your code like this:
If bEventsEnabled then
'your code here
Endif

and set bEventsEnabled to False when you don't want the event code to run.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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