Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Detecting user action

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bo Hansson - 02 Oct 2004 23:38 GMT
How do I detect the event when a user puts the insertion point into a
specific table in a document?

/BosseH
Jay Freedman - 03 Oct 2004 01:01 GMT
>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
Jean-Guy Marcil - 03 Oct 2004 15:27 GMT
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?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.