Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I select the first 2 rows of a table in word 2

Status
Not open for further replies.

nodrog77

Programmer
Sep 26, 2007
47
AU
Hey there,

this is a pretty simple question - I just need help because when I run the macro recorder I can't select stuff with the mouse, I need to select the first 2 rows in a table in Word so I can set them as header rows: eg.

'Set the first two rows as repeatable heading rows
' This ain't workin'....
Selection.Tables(1).Range(Start:=Selection.Tables(1).Rows(1), End:=Selection.Tables(1).Rows(2)).Select
.....
Selection.Rows.HeadingFormat = True

I just need to know how to do selections or define ranges in word VBA and I just can't get it right at the moment

Thanks,
Lea
 
Actually I figured I better learn my keyboard shortcuts again - this looks like it worked:

'Set the first two rows as repeatable heading rows
Selection.Tables(1).Rows(1).Select
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Rows.HeadingFormat = True

Probably defining a range would be cleaner so the first question is still valid
 
You don't need to select the rows ...

Code:
[blue]Selection.Tables(1).Rows(2).HeadingFormat = true
[/blue]

When recording a macro, you can still use the arrow keys to move around, and select content in, the document. You do end up with a lot of extra stuff recorded for the repeated changes in the Selection, but you can ignore it.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
You may try this:
Code:
With Selection.Tables(1)
  .Rows(1).HeadingFormat = True
  .Rows(2).HeadingFormat = True
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
RE: mouse restrictions when recording a macro. You can also often use Shift-F10, which is the keyboard equivalent to a right click. This still works when recording macros.

PHV, while perhaps odd, Tony's code is correct, and you not need to explicitly set Row(1).HeadingFormat=True. VBA will do it for you.

In fact, you do not need to explicitly set ANY proceeding row. Word VBA assumes that if Row(x).HeadingFormat = True, then ALL proceeding rows are part of the repeating heading, as they must be.
Code:
Selection.Tables(1).Rows(6).HeadingFormat = True
means rows 1 through 5 will be - MUST be - included (along with row(6) of course) as part of the repeating heading.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top