none
Select Table as Range relative to selection RRS feed

  • Question

  • I simply want to select the table above my selection as a range. To select a table that I am currently active in, I would use .Range.InRange(Selection.Tables(1).Range. But I want to select a table directly above that. Can anyone please tell me how?

    Friday, July 27, 2012 12:32 AM

Answers

  • Sub ScratchMacro()
    'A quick macro scratch pad created by Greg Maxey
    Dim oTbl As Word.Table
    Dim i As Long
    If Selection.Range.Information(wdWithInTable) Then
      i = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count
      If i > 1 Then
        Set oTbl = ActiveDocument.Tables(i - 1)
        oTbl.Select
      End If
    End If
    End Sub

    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    • Marked as answer by tonayie Friday, July 27, 2012 3:59 AM
    Friday, July 27, 2012 3:38 AM

All replies

  • Sub ScratchMacro()
    'A quick macro scratch pad created by Greg Maxey
    Dim oTbl As Word.Table
    Dim i As Long
    If Selection.Range.Information(wdWithInTable) Then
      i = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count
      If i > 1 Then
        Set oTbl = ActiveDocument.Tables(i - 1)
        oTbl.Select
      End If
    End If
    End Sub

    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    • Marked as answer by tonayie Friday, July 27, 2012 3:59 AM
    Friday, July 27, 2012 3:38 AM
  • i was trying so hard not to bother you, but it worked, perfectly. exactly as intended. amazing! you're really are a great human being. this was the final plight in this project too. thank you so so much.
    Friday, July 27, 2012 3:59 AM