Bo Hansson said:
How do I detect the event when a user puts the insertion point into a
specific table in a document?
/BosseH
Hi Bo,
You need an application event handler class. This isn't really as
complicated as it sounds. For the basics, see
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm.
For this specific job, follow the instructions in the AppClassEvents
page for creating a global template and setting up the module and
class module. For step 6, use the following code in the
ThisApplication class module:
Private Sub oApp_WindowSelectionChange(ByVal Sel As Selection)
If Sel.Information(wdWithInTable) Then
If ActiveDocument.Tables.Count > 1 Then
If Sel.Range.InRange(ActiveDocument.Tables(2).Range) Then
StatusBar = "In table 2"
End If
End If
End If
End Sub
Change the "ActiveDocument.Tables(2).Range" bit to detect the specific
table you have in mind. Replace the StatusBar statement with whatever
action you want to execute when the selection is in that table.
Be aware that this handler will execute every time the selection
moves, including when it moves from one place in the table to another
place in the same table. If your action should be executed only once,
on entering the table from outside, then you have to supply the
necessary logic to suppress the action when it isn't wanted.