PDA

View Full Version : Solved: Select Multiple Rows in Table?



DekHog
09-12-2012, 07:06 AM
Guys, how do I select multiple rows in a table using VBA?

I can select one row using ActiveDocument.Tables(1).Rows(1).Select

This will select the first row of the first table; what I need is to select the first three rows of the first table, but am struggling!

I need to run this on 650 documents, so not using VBA isn't an option!!

TIA

Frosty
09-12-2012, 01:35 PM
Try something like this...


Sub Demo()
Dim rngFirstThreeRows As Range
With ActiveDocument.Tables(1)
Set rngFirstThreeRows = .Rows(1).Range
rngFirstThreeRows.End = .Rows(3).Range.End
End With
rngFirstThreeRows.Select
End Sub

HOWEVER -- you probably don't need to select these rows at all in order to do what you actually want to do. You can get a little more help if you give some specifics.

But your final code will run significantly faster on 650 documents if you don't select anything.

DekHog
09-12-2012, 01:43 PM
Thanks - haven't tried it yet as the files are at work. Not very good at this stuff at all, so have been using MultiMacro to do the hard work and just selecting my saved macros one at a time to do what I need, and it's been doing quite well!

What needs to be done now is to change the first three rows of the first table in each document from dotted horizontal lines to solid lines, but I can't see how you can do this without selecting them? You can't select rows etc in a table while recording a macro, so impossible for me to do it that way.

Frosty
09-12-2012, 02:03 PM
Sorry, I don't know what MultiMacro is, so I don't know what hard work it is helping you do... but...

You can select rows while recording a macro-- you just have to use the keyboard to do it (i.e., hold down the shift key, then use some combination of arrow keys/home key/end key/ctrl key, etc etc).

That will give you the basics of how to apply borders to *something* -- from there, you can usually translate the recorded macro (which does use the selection) to something which does not use the selection (and is thus, faster).

DekHog
09-12-2012, 02:08 PM
Thanks, I never knew you could do that with the keyboard, I'll give it a try.

MultiMacro; you save your macros; list them by name in an open word document and leave it open. Run the MultiMacro addin, and it lets you select a folder then applies the listed macros to all documents in the folder......

fumei
09-13-2012, 01:51 PM
MultiMacro...essentially the DIR function...