#1
|
|||
|
|||
Include/Exclude Table(s) from OnEnter event
I have a word (10) document with 17 tables in it. I want to run an OnEnter event that only applies to tables 2, 4, 5, 6, 8, 9, 10,& 11. There is no data or active content in tables 3 & 7 so I suppose I could use a range (Tables 2-11) but I'm having trouble with the syntax. |
#2
|
||||
|
||||
Word has no OnEnter event. Aside from intercepting events like Save and Print, you can use a class module to capture a limited range of events:
• Quit • DocumentChange • DocumentBeforeClose • DocumentBeforePrint • DocumentBeforeSave • DocumentOpen • NewDocument • WindowActivate • WindowBeforeDoubleClick • WindowBeforeRightClick • WindowDeactivate • WindowSelectionChange You could use the last of these to test whether the user has clicked in a table. For some code you could adapt to that end, see: http://word.mvps.org/FAQs/Customizat...PlusHeader.htm
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Meant ContentControlOnEnter (sorry)
|
#4
|
||||
|
||||
See, for example: https://www.msofficeforums.com/word-...html#post85389. The ContentControlOnEnter code used in the attachment there excludes the first & last tables in the document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
If I read the example correctly, this is the part I'm interested in (along with the Dim statements).
Code:
Set CCtrlRng = CCtrl.Range If CCtrlRng.Information(wdWithInTable) Then Set TblRng = CCtrlRng.Tables(1).Range i = .Range(0, TblRng.End).Tables.Count If (i = 1) Or (i = .Tables.Count) Then Exit Sub Code:
Set CCtrlRng = CCtrl.Range If CCtrlRng.Information(wdWithInTable) Then Set TblRng = CCtrlRng.Tables(1).Range i = .Range(0, TblRng.End).Tables.Count If (i = 1) Or (I < .Tables(12) Then Exit Sub |
#6
|
||||
|
||||
Your implementation suggests you want to exclude tables 1 - 11. In that case, you should use:
If i < 12 Then Exit Sub However, your first post said: Quote:
If (i = 1) Or (i = 3) Or (i = 7) Or (i >11) Then Exit Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Got It!
How do I mark it solved? |
#8
|
||||
|
||||
From the 'Thread Tools' dropdown at the top of the thread page. Done.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Table of content to not include TOC as first section!? | neuroscientist911 | Word | 4 | 11-19-2014 07:55 AM |
Docx to PDF: Exclude heading from TOC but include in bookmarks | Lebber | Word | 8 | 12-04-2013 06:11 AM |
Include a table in landscape but keep footnote continuous | prakash | Word Tables | 6 | 11-30-2013 04:09 PM |
VBA: Include Dynamic Sheet Name In Pivot Table Source Data | ibrahimaa | Excel Programming | 2 | 04-28-2012 12:27 AM |
Include headers in table of contents | bwhight | Word | 1 | 10-10-2006 08:59 AM |