Results 1 to 2 of 2
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.
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...