2011-10-10, 08:54 #1
- Join Date
- Jun 2002
- Thanked 0 Times in 0 Posts
Determine which table... MSWord 2003
I have a document with a variable number of tables in it. There is a piece of text that always appears, and is always contained within row 1, cell2 of either table 1 or table 2.
How would I determine in a VBA function which table the text appears in?
Any advice would be gratefully received.
Subscribe to our Windows Secrets Newsletter - It's Free!
Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!
+ Get this BONUS — free!
Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!
2011-10-10, 13:46 #2
- Join Date
- Feb 2001
- Silicon Valley, USA
- Thanked 93 Times in 89 Posts
This approach is a bit of a blunt instrument, but it might work for your purposes. It creates a range from the end of the Selection to the beginning of the content and then reports the number of tables in the range, on the theory that the selection must be in the last table.
Sub SelectionIsInTableNumber() If Selection.Information(wdWithInTable) Then Dim rngTemp As Word.Range Set rngTemp = ActiveDocument.Range(ActiveDocument.Content.Start, Selection.End) MsgBox rngTemp.Tables.Count, vbInformation + vbOKOnly Set rngTemp = Nothing Else MsgBox "Not in a table", vbExclamation + vbOKOnly End If
Last edited by jscher2000; 2011-10-10 at 13:47. Reason: Hmmm...