Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference the table that the user's cursor is (Word 2003)

Status
Not open for further replies.

squishiddy

Programmer
Nov 15, 2002
5
CA
Hey Everyone.

I have a quick question that one of you can hopefully answer.

I currently have code that enters a table onto a Word document.

If the user puts their cursor in any cell in the table, how can i reference the table that the cursor is in from my code?

Thank a bunch in advance! ~o)
 
Something like this :-

'----------------------------------------------------
Sub test()
Dim MyColumn As Integer
Dim MyRow As Integer
If Selection.Information(wdWithInTable) = True Then
MyColumn = _
Selection.Information(wdStartOfRangeColumnNumber)
MyRow = _
Selection.Information(wdStartOfRangeRowNumber)
MsgBox ("Column " & MyColumn & vbCr & "Row " & MyRow)
Else
MsgBox ("Selection is not within a table.")
End If
End Sub
'--------------------------------------------------------


Regards
BrianB
Use CupOfCoffee to speed up all windows applications
================================
 
Hi squishiddy,

Provided the Selection (cursor) is within a table, you can reference the whole table directly ..

Code:
[blue]Dim t As Table
If Selection.Information(wdWithInTable) Then
    Set t = Selection.Tables(1)
    MsgBox "Table has " & t.Rows.Count & " Rows and " & t.Columns.Count & " Columns."
Else
    MsgBox "Please place your cursor within a Table"
End If[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks a bunch guys!!!

Beats searching through tons of vba help files.

~o)

Christy

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top