A family of Microsoft word processing software products for creating web, email, and print documents.
Think I've fixed it!
For future reference:
In first class module cAppEventClass:
Public WithEvents wdAppEvents As Application
Private Sub WdAppEvents_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
Set wdDoc.wdDocEvents = Doc
Debug.Print "Activated " & Doc.name
End Sub
In second class module cDocEventClass:
Public WithEvents wdDocEvents As Word.Document
Private Sub wdDocEvents_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Debug.Print Now
End Sub
Private Sub wdDocEvents_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Debug.Print Now
End Sub
In a normal code module, and set up to run when Word starts, e.g. via ribbon OnLoad event, or AutoExec procedure:
Public wdApp As New cAppEventClass
Public wdDoc As New cDocEventClass
Sub AutoExec()
Set wdApp.wdAppEvents = Application
' Set wdDoc.wdDocEvents = ActiveDocument 'Do not do this here - there won't be an ActiveDoc when this code runs!
End Sub
Now when I click in and out of a ContentControl in ANY open document, the relevant Document event fires!
Cheers
Rich