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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set "repeat as header row" from VB? 2

Status
Not open for further replies.

wordsearch

Programmer
Feb 14, 2004
5
GB
In Microsoft Word, you can right-click on the first row in a table and select table properties. In table properties, you can tick a checkbox whose caption is something like "Repeat as header row on each page".

(This has the effect of displaying the first row of the table at the top of each page).

Does anyone know how to do this using VBA / Office automation?

In other words, can the "Repeat as header row on each page" option be set programmatically from Visual Basic?

I know how to create Word documents and tables from VB, I just don't know how to set this option on them.
 
Hi wordsearch,

Have you tried recording yourself doing this? That would seem to be an easy way to start. What you want is ..

Code:
ActiveDocument.tables(1).rows(1).headingFormat = True

.. or something similar.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Thanks Tony!

That was what I was looking for.

Tell me more about how I can record myself doing this - is there a way I can do stuff in Word and it will tell me what the VBA commands are (excuse my ignorance)?



 
Hi wordsearch,

Recording yourself is a good way to get started and to find out how to do particular things. The code that's generated is probably never the best or most efficient but it points you in the right direction.

In Word ..

Select Tools > Macro > Record New Macro
In the popup Dialog, (optionally) alter any bits you feel like and press OK
Do whatever you want. You will find you can't do some things with the mouse while recording.
When you've done what you want, click on the square on the Stop Recording Toolbar (which will have appeared when you started recording).

Now Press <Alt><F11> to open the VB Editor.

In the Project Explorer Pane on the left (if its not there press <Ctrl><R> to get it) find where you recorded the macro to - if you accepted the default it will be in a Module (Module1 or NewMacros, probably) under Modules under Normal, and double click it to open it in the pane on the right.

Look at, and play with, the code.

Hope that's enough to get you going.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Another little hint. It is true that recording macros does disable some mouse events - however, when it declines to do a right mouse click, try using Shift-F10. This is the keyboard equivalent to right click and sometimes allows you to record things when the right click is disabled.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top