View Single Post
 
Old 12-17-2021, 10:25 AM
daneyuleb daneyuleb is offline Windows 10 Office 2016
Novice
 
Join Date: Dec 2021
Posts: 3
daneyuleb is on a distinguished road
Default

OK, figured it out. Followed MS's instructions on creating an event-handler object:

Using events with the Application object (Word) | Microsoft Docs

In case anyone else ever needs something like this, it was simple:

Create a class module:

Insert -> Class Module

In the View -> Properties window, give your new module a name. (I just used MS's example: EventClassModule )

In the class module, put this at the top to declare an object with events:

Code:
Public WithEvents App As Word.Application
Click your new object ("App") in the Object dropdown, and you'll see all the interesting events you can use with your new object in the Procedures drop-down to its right -- there's lots! I picked the WindowActivate one for what I needed:

Code:
Private Sub App_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)

MsgBox "Active!"

End Sub
The last thing is to connect your new class object ("App") to the Word.Application object. Which is just this code in any module.
Code:
Dim X As New EventClassModule

Sub Register_Event_Handler()

Set X.App = Word.Application

End Sub
Run this Register_Event_Handler sub, and the Event becomes active. Each time I come back to the word doc from another app, it triggers! Perfect!
Reply With Quote