Closed Thread
Results 1 to 5 of 5

Finding location in Word works from Word but not from Excel

Hybrid View

  1. #1
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372
    Hi Wayne,

    my first hunch: in the Excel VBA Editor go Tools - References and check the box for

    Microsoft Word 11.0 Object Library

    The 11.0 is for Office 2003, if you're using a different version it will be a different number.

    cheers

  2. #2
    Registered User
    Join Date
    12-03-2008
    Location
    New Zealand
    Posts
    5

    References

    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

  3. #3
    Registered User
    Join Date
    12-03-2008
    Location
    New Zealand
    Posts
    5

    Smile Solved :)

    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

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    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 assisted or failed to assist you I welcome your Feedback.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1