Thanks for that thought Teylyn
I have Word 11 referenced as well as Excell 11, Office 11, VB for Applications and OLE Automation
Do I need all these ?
Thanks
Wayne
Thanks for that thought Teylyn
I have Word 11 referenced as well as Excell 11, Office 11, VB for Applications and OLE Automation
Do I need all these ?
Thanks
Wayne
Becuase I was running the macro in Excel I had to qualify the Selection methods as Word - not Excel
This code works from Excel
Wayne
Sub WhereAreWe()
' Works in Excel
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange As Word.Range
Dim oSelection As Word.Selection
Dim TableIndex, CurrentRow, CurrentColumn, NoOfTables As Integer
Set oWord = GetObject(, "Word.Application")
Set oDoc = oWord.ActiveDocument
NoOfTables = oDoc.Tables.Count
' Which table are we in ?
' Range from Table(1) to position of Cursor
Set oRange = oDoc.Range(0, oWord.Selection.Tables(1).Range.End)
' Count number of tables in range (= index of table that Cursor is in
TableIndex = oRange.Tables.Count
' Which cell in this table ?
CurrentRow = oWord.Selection.Information(wdStartOfRangeRowNumber)
CurrentColumn = oWord.Selection.Information(wdStartOfRangeColumnNumber)
MsgBox "Table Number: " & CStr(TableIndex) & vbCrLf _
& "Row Number: " & CStr(CurrentRow) & vbCrLf _
& "Column Number: " & CStr(CurrentColumn)
End Sub
wayneh
Please take a couple of minutes and read the Forum Rules your posting s break rule 3
Please Read Forum Rules Before Posting
Wrap VBA code by selecting the code and clicking the # icon or Read This
How To Cross Post politely
Top Excel links for beginners to Experts
If you are pleased with a member's answer then use the Scales icon to rate it
If my reply has assistedor failed to assist you
I welcome your Feedback.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks