Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2015, 11:15 AM
warbird warbird is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 64bit
Novice
Include/Exclude Table(s) from OnEnter event
 
Join Date: Jun 2015
Posts: 13
warbird is on a distinguished road
Question 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.
Reply With Quote
  #2  
Old 07-10-2015, 07:52 PM
macropod's Avatar
macropod macropod is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-13-2015, 05:47 AM
warbird warbird is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 64bit
Novice
Include/Exclude Table(s) from OnEnter event
 
Join Date: Jun 2015
Posts: 13
warbird is on a distinguished road
Default

Meant ContentControlOnEnter (sorry)
Reply With Quote
  #4  
Old 07-13-2015, 05:55 AM
macropod's Avatar
macropod macropod is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 07-13-2015, 06:39 AM
warbird warbird is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 64bit
Novice
Include/Exclude Table(s) from OnEnter event
 
Join Date: Jun 2015
Posts: 13
warbird is on a distinguished road
Default

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
In my case it should look like This (?)
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
Thanks for your incredibly prompt response!
Reply With Quote
  #6  
Old 07-13-2015, 03:19 PM
macropod's Avatar
macropod macropod is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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:
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
In that case, you should use:
If (i = 1) Or (i = 3) Or (i = 7) Or (i >11) Then Exit Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-14-2015, 05:06 AM
warbird warbird is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 64bit
Novice
Include/Exclude Table(s) from OnEnter event
 
Join Date: Jun 2015
Posts: 13
warbird is on a distinguished road
Default

Got It!

How do I mark it solved?
Reply With Quote
  #8  
Old 07-14-2015, 05:10 AM
macropod's Avatar
macropod macropod is offline Include/Exclude Table(s) from OnEnter event Windows 7 64bit Include/Exclude Table(s) from OnEnter event Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by warbird View Post
How do I mark it solved?
From the 'Thread Tools' dropdown at the top of the thread page. Done.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



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
Include/Exclude Table(s) from OnEnter event Docx to PDF: Exclude heading from TOC but include in bookmarks Lebber Word 8 12-04-2013 06:11 AM
Include/Exclude Table(s) from OnEnter event Include a table in landscape but keep footnote continuous prakash Word Tables 6 11-30-2013 04:09 PM
Include/Exclude Table(s) from OnEnter event 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft