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

VBA and Word 1

Status
Not open for further replies.

TomG1

Programmer
Apr 12, 2001
25
BE
Hi all,

I 've got a problem.

I'm filling a table in Word with VBA-code. everytime I want to show something in the table I'm adding a lineand putting the text in it. So far so good.

Now how can I know when the table continues on the next page, because the header should be the same on al of the pages

I hope someone can help
 
Are you building a Word Table object, or just formatting text lines? If you're creating a Table object, all you have to do is set the table.Rows(1).HeadingFormat = True. Windows will automatically repeat the headings row after a page break.

If you're just formatting text lines, you'd probably have to dead-reckon where the page break occurs, based on the length of the paper you intend to print on, the height of the font, the current line spacing settings, the sizes of the margins, page header, and page footer, and maybe other things. It hurts my brain to even think about having to do that! X-) Rick Sprague
 
Thx a lot Rick !!

I have one more question. The user of the program want a possibility to change the text i the header, but now I've noticed that whit that code it doens't seem possible.

Is there a way to let the users change the header for example on the second page?
 
Your users are weird! (At least it seems that way to me, because I don't know what this table is all about.)

The data in a table is generally homogeneous. All the data in a column is expected to express the same kind of information. Changing a header seems like it would mean you're starting a new and different table. And how would that we synchronized with a page break, anyway?

So maybe you should give them a way to end the first Table object, and start another one, which would have its own headers. Are you already giving them the ability to break the page at a specified row? That would be the perfect time to ask if they want to change the headers.

Unless you really are planning to use the dead-reckoning approach, that is, in which case I'm afraid you're on your own. Rick Sprague
 
Hi,

Maybe it's a good idea if I would explain what kind of table it is. So here goes.

It's a contract. (sale, rent,...) The users first fill in some fields in an application written in system Z. this application gets this information and puts it in a textfile. This is where I come in, I have to generate a contract in Word, by getting the information out this textfile and putting it in a template in Word.

But the users told me that it is possible that in one contract the estimated time you rent something is different for some things. So they would like to change the header from : "Rent over 2 years", to , "Rent over 3 years".

I hope it's more clearly now.
 
I'm afraid it's not really not all that clear, yet, but it gives me the basis for asking clarifying questions.

I don't really get why you would have a table in a contract. Is it perhaps a payment schedule? I'm having some doubt now whether you're really talking about a row of table headers, or an ordinary page header. Where should &quot;Rent over <n> years&quot; appear--at the top of the page, or in the first row of whatever this table is about?

How is the template document structured? Does it already contain the table, and you're just filling it in? Does the template contain page headers? (A multi-page contract would normally have an empty first-page header and a distinct header for subsequent pages.) Rick Sprague
 
Hi,

the table is build up like this

this is the header (must come on top of each page)

&quot;Description Unit Price, rent/month Quantity Price, rent/month on 4 years&quot;



after this I have to fill up lines in this table.

for example

&quot;something they sell 123.456 1 123.456&quot;

Now the header with 4 years in it comes on top of al of the pages.
The users want the possibility to change the 4 years into 3 years or something like that on for example the second page. And now they can only change the header on the first page, and if they do, al the headers change with it.
The want that on the first page it shows 4 years, and that they manually can change the number of years on the next pages.

By the way, I can totally understand that the users are pretty weird :)
 
I see, you're talking about page headers and not table header rows.

What you need to do is insert a section break (with the new page option) everywhere you want a new header. Page headers belong to the section they're in. Each page within a section has the same headers.

I really can't help you work out the code to do this; I'm not familiar with it, and it would take more time than I have available. But here are some of the things you'll use:
ActiveDocument.Sections.Add , wdSectionNewPage
ActiveDocument.Sections(n).Headers(wdHeaderFooterPrimary).Range.InsertBefore &quot;your header text&quot;

Use the Office 2000 Object Model Guide (a booklet that comes with Office 2000 Developer Edition) and the Object Browser to help you understand the object hierarchy.

Or, if your users are willing, they can insert the section break and page header themselves, using the Insert>Break and View>Header And Footer menu commands.

Good luck! Rick Sprague
 
Hi,

I've explained the previous wrongly, sorry for that.

They are table header rows. But with the code you gave me: table.Rows(1).HeadingFormat = True.

if a table continues on another page the same header appears (thx again for that). But you can't change the table header on that second page, is there a way to do this?

I hope that I've expressed myself a bit better now
 
I think your best bet is to insert a page break, followed by a second table with a new header row. That would start with ActiveDocument.Tables.Add, but I'm afraid you're getting beyond my limited experience with Word object model now. Rick Sprague
 
RickSpr - I am unsure if you are stilling checking this thread, but I have run into a similar issue and would appreciate your insight.

I have created code in Access 2000 that populates a Word template (through bookmarks). The last bookmark is for a table (created based on an Access query). Even though I have the following line of code, I cannot get the header row to repeat:
With objTable
' Add a new row on top and make it a heading
.Rows.Add(.Rows(1)).HeadingFormat = True


I am confused with this because everything I have read seems to indicate that my code should cause the Header row to repeat on each page. Again, I would appreciate any feedback that you may have...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top