Select continuous cells in a Word table column

Posted on 2012-08-27
Last Modified: 2012-08-28
With VBA in Word 2010, if I have

     Dim col as Column
     set col = Activedocument.tables(1).columns(3)

is there not a short, one-line command to select cells x to y in that column?
I'd even take a two or three line command.
Question by:JohnRobinAllen
    LVL 59

    Expert Comment

    by:Chris Bottomley
    Short ... not especially unless you split it down into ranges and then recombine but the net effect either via a with or ranges is as follows~:

    activedocument.range(activedocument.tables(1).columns(1).cells(2).Range.Start, activedocument.tables(1).columns(1).cells(4).Range.end).Select

    LVL 59

    Assisted Solution

    by:Chris Bottomley
    i.e. via ranges:

    Sub aRange()
    Dim rngFirst As Range
    Dim rngLast As Range
        Set rngFirst = ActiveDocument.Tables(1).Columns(1).Cells(2).Range
        Set rngLast = ActiveDocument.Tables(1).Columns(1).Cells(4).Range
        ActiveDocument.Range(rngFirst.Start, rngLast.End).Select
    End Sub

    Open in new window

    or via 'with'

    Sub bRange()
        With ActiveDocument.Tables(1).Columns(1)
            ActiveDocument.Range(.Cells(2).Range.Start, .Cells(4).Range.End).Select
        End With
    End Sub

    Open in new window

    LVL 76

    Accepted Solution

    Be a bit careful if you want to use the selection programatically.

    Selection.Text returns the contents of the first cell only

    Select.Range.Text includes the contents of cells from other columns that are between the first and last cell

    Author Closing Comment

    Chris solved the problem and gets full credit. Graham's comment is important and deserves extra points for it. Thanks to both.<br />     It is a sunny day today in Priddis, Alberta, both outside (with the weather) and inside (thanks to the solution provided above). <br />     
    LVL 76

    Expert Comment

    It's sunny where I am the UK today as well. Chris is about 100 miles north, but I guess that it's about the same.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
    Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
    This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
    This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now