>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.
--
Regards,
Jay Freedman http://aspnet2.com/mvp.ashx?JayFreedman
Microsoft Word MVP FAQ: http://word.mvps.org
Bonjour,
Dans son message, < Bo Hansson > ?crivait :
In this message, < Bo Hansson > wrote:
|| How do I detect the event when a user puts the insertion point into a
|| specific table in a document?
Jay's answeer was excellent, but I tought I'd warn you about a potential
problem.
Be careful about using the table index in the code. If the user adds/removes
tables in the document, then this index will change.
Or did I miss something?

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Jay Freedman - 04 Oct 2004 04:29 GMT
>Bonjour,
>
[quoted text clipped - 11 lines]
>
>Or did I miss something?
Jean-Guy, you're absolutely correct. That's what I meant when I said
'Change the "ActiveDocument.Tables(2).Range" bit to detect the
specific table you have in mind.' It's good to emphasize the point,
though. Since I don't know exactly how Bo defines 'a specific table',
I can't suggest a better way of determining whether the table
containing the selection is the 'right' one.
--
Regards,
Jay Freedman http://aspnet2.com/mvp.ashx?JayFreedman
Microsoft Word MVP FAQ: http://word.mvps.org
Jean-Guy Marcil - 04 Oct 2004 14:10 GMT
Bonjour,
Dans son message, < Jay Freedman > ?crivait :
In this message, < Jay Freedman > wrote:
>> Bonjour,
>>
[quoted text clipped - 8 lines]
>>
>> Be careful about using the table index in the code. If the user
adds/removes
>> tables in the document, then this index will change.
>>
[quoted text clipped - 6 lines]
> I can't suggest a better way of determining whether the table
> containing the selection is the 'right' one.
Bookmarking the table and checking for to see if the cursor is in the
bookmark range?
Would that work?

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Howard Kaikow - 04 Oct 2004 06:32 GMT
One way might be to assign the table range to an object, then test for that
range instead of the table index.

Signature
http://www.standards.com/; See Howard Kaikow's web site.
> Bonjour,
>
[quoted text clipped - 11 lines]
>
> Or did I miss something?
Bo Hansson - 01 Dec 2004 19:46 GMT
Thanks for the warning,
However, I believe that I have managed to identify the specific tables by
checking unique headings within them.
/BosseH
> Bonjour,
>
[quoted text clipped - 12 lines]
>
> Or did I miss something?