Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4064606
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:52:36+00:00 2026-05-20T15:52:36+00:00

I have a macro enabled template with an event listener that listens for content

  • 0

I have a macro enabled template with an event listener that listens for content control exit events. The idea is that when the “title” or “date” content controls on the title page of the document are edited, we automatically update the “title” and “date” content controls in the header so that the author doesn’t have to enter the same content twice.

My problem is that, when I open a new document based on my template (right click template => new, or just double click it), these events only fire for the very first instance of a content control being exited. I click inside the CC, click outside the CC, get a MsgBox indicating that my event has fired. I then try that a second time: click inside the CC, click outside the CC and do not get a MsgBox.

Code from my event handler class:

Public WithEvents doc As Word.Document

Private Sub doc_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    MsgBox ContentControl.Range.Text    
End Sub

I’ve checked and found that my event handler object is still defined (not “Nothing”) in my NewMacros, it’s just that it isn’t getting ContentControlOnExit events, or is ignoring them.

If I change the above code such that I’m not actually doing anything with the content control inside the event body, the problem is fixed – my theory is that touching any sort of content control while inside the ContentControlOnExit event is triggering recursive ContentControlOnExit events and somehow causing a problem. Obviously a ContentControlOnExit event is pretty useless if I’m not allowed to do anything with content controls while inside it.

i.e. receiving a ContentControlOnExit event doesn’t “break” future ContentControlOnExit events if I change my code to:

Public WithEvents doc As Word.Document

Private Sub doc_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    MsgBox "Content Control exit event"
End Sub

I’ve tried using an eventsEnabled boolean to try and guard against doc_ContentControlOnExit being called recursively in case that’s the problem, but it didn’t help. The code I used for that was like:

Sub Class_Initialize()
    pEventsEnabled = True
End Sub

...

' in the doc_ContentControlOnExit sub:
If pEventsEnabled Then
    ' obvious race condition...
    pEventsEnabled = False
    ' Fiddle around with some content controls
    pEventsEnabled = True
End If

Excel has an Application.EnableEvents property, but this doesn’t seem to be present in Word.

The interesting thing is that this all works fine when editing the template itself, just not for documents based on that template. When editing the template, I get a ContentControlOnExit event every time I exit a content control, and all of my code works fine.

If it helps, I’m using Word 2010 (Office Professional Plus) on Windows 7 Professional 64 bit. I’ve also confirmed that the same problem occurs under Word 2007.

edit:

I just tried setting the event handler object to call “ReincarnateEventHandler” in NewMacros, which in turn set the original event handler object to Nothing and then instantiated a new event handler. This resulted in an infinite loop of event handlers handling the first event and then setting up a new event handler which then handled the same (original) event. Using Application.OnTime to delay the reincarnation by 1 sec fixed the infinite loop, but didn’t fix the original problem — i.e. dropping my first event handler and then instantiating a new event handler doesn’t let me catch subsequent events after the first event.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:52:37+00:00Added an answer on May 20, 2026 at 3:52 pm

    It’s a quick fix. Change ThisDocument to ActiveDocument in your SetUp routine. As it is, ThisDocument refers to the template itself. ActiveDocument is for the one created from AutoNew. So it should read Set eventHandler.doc = ActiveDocument.

    It won’t interfere with other documents not created with “so_template.dotm” as the ones created from that template will have an .AttachedTemplate of “so_template.dotm” and the AutoNew, if present, will control them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.