How to loop a certain header with a certain condition

E

edwinf

I have my program that has different header text in every page. How would i
do that? Anything has an idea of this? Thanks in advance...
 
E

edwinf

I can't find button to edit my post, so i just added this as my sample to my
problems.. thanks

If page = 1 Then
.Rows(1).Cells(1).Range.Text = "Header for Page 1"
Else
.Rows(1).Cells(1).Range.Text = "Header for Other Pages"
End If
 
O

old man

Hi,

If you are using Word 2003 and above there is a pages collection (and page
object) which allows manipulation by page. Here is a bit of code I wrote.
First I used the page object to goto to a specific page and then typed to the
page. Then I realized I could just use the goto next construction. You may
also want to change the code to use range objects instead of selection object.

By the way Word headers are really attached to a section and not to a page.
If you want to have a unique header for every page you should investigate
using fields (the 'cleaner' solution) or you should create a new section for
every page.

Old Man

Sub n1()

Dim objPage As Page
Dim j1 As Integer

' start at page 1
Selection.HomeKey Unit:=wdStory
'j1= number of pages in document
j1 = ActiveDocument.ActiveWindow.Panes(1).Pages.Count
For k1 = 1 To j1


' Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Name:=Str(k1)
Selection.TypeText "Page - " & k1 & vbCrLf
Selection.GoTo what:=wdGoToPage
Next
End Sub
 
E

edwinf

I did what your code is, but still its lacking. Scenario like this: I have
some tables who has a long paragraph cutting through the next page, when that
code you gave pass through that paragraph (which i placed after the header),
the continued paragraph was already broken. Like, i set that paragraph
indented by 5 on the first sentence, the next line which is on the next page
was also indented same with the first.

Drafting like this:
-HEADER
-The LOOPING BODY (which you gave) consist of only 3 lines
-TABLE 1 (long paragraph)
-TABLE 2 (long paragraph)
-Other TABLES (long paragraph too)
 
O

old man

Hi,

I am unclear what you are trying to do. Are you trying to insert the page
number at the top of every table or in the top of a long table (which spans
many pages) i.e. you want to have the top of every page (not in the header
-just on top of the table) the page number? If so you really should use a
field.

Old Man
 
E

edwinf

Thanks for the reply... I think the best way is to put it together with the
Header so that the tables won't rumbled. The thing is, i don't know what to
do, and if that fields you're saying is good, i still don't know it. Im just
new to this kind of programming... Will you still help me please?

Thanks again Old Man!
 
R

Russ

This is from Word Help:Repeat a table heading on subsequent pages
1. Select the row or rows of text that you want to use as a table heading.
The selection must include the first row of the table.
2. On the Table menu, click Heading Rows Repeat.
Notes
€ Microsoft Word automatically repeats table headings on new pages that
result from automatic page breaks. Word does not repeat a heading if you
insert a manual page break within a table.
€ Repeated table headings are visible only in page layout view or when you
print the document.
See also
Break a table across pages
About tables
 
E

edwinf

I just browse this today bec. I just came from a vacation. I think this is
useful but frankly speaking, i don't have an idea on how or what to do with
this, i am just a newbie of VBA-MS Word really. Will you help me creating the
codes? This will help me alot.... Thanks again Mr./Ms. Russ
 
J

Jonathan West

edwinf said:
I just browse this today bec. I just came from a vacation. I think this is
useful but frankly speaking, i don't have an idea on how or what to do
with
this, i am just a newbie of VBA-MS Word really. Will you help me creating
the
codes? This will help me alot.... Thanks again Mr./Ms. Russ

You don't need any VBA. Read the instructions carefully. They are for
actions you carry out in Word itself, not in the VBA editor.
 
E

edwinf

Aw sorry, i didn't get it... By the way, i need the codes bec. i will use
this to transfer my data to MS Word. Please review all topics i wrote...
Thanks
 
J

Jonathan West

edwinf said:
Aw sorry, i didn't get it... By the way, i need the codes bec. i will use
this to transfer my data to MS Word.


Set the HeadingFormat property to True for the first row of the table. There
is a code example in the VBA Help.
Please review all topics i wrote...

Sorry, can't do that. I answer questions in my (limited) spare time and
therefore work as efficiently as I can. That means answering specific
questions that are clear enough to give an unabiguous answer.
 
E

edwinf

Jonathan West said:
Set the HeadingFormat property to True for the first row of the table. There
is a code example in the VBA Help.

Im sorry, but you didn't get what i mean, or i think something is lacking.
Here's the simplest way to what my problem is:

On the first page, i have to put the ff Headings:
Republic of the Country
11th Session
Series of 2005

On the second page and so forth:
Resolution No. 12345
July 15, 2007
Page two (Page three, Page four........)

That's the exact sample... How can i do that? I know you have an idea of
this, you and other Guru's help is badly needed!
Thanks! :)
 
J

Jonathan West

edwinf said:
Im sorry, but you didn't get what i mean, or i think something is lacking.
Here's the simplest way to what my problem is:

On the first page, i have to put the ff Headings:
Republic of the Country
11th Session
Series of 2005

On the second page and so forth:
Resolution No. 12345
July 15, 2007
Page two (Page three, Page four........)

That's the exact sample... How can i do that? I know you have an idea of
this, you and other Guru's help is badly needed!
Thanks! :)

We are getting mixed up between two quite separate things - the heading row
of a table, and the header area of a page.

If you want a separate first page header, then go to File, Page Setup, click
the Layout tab of the dialog, and check the "Different first page" checkbox.

Scroll to the first page of your document, and then go to View, Header and
Footer. The cursor should now be flashing in an area labelled "First Page
Header". Type or paste this text into the header

Republic of the Country
11th Session
Series of 2005

Scroll down to the next page, where the header area should simply be
labelled "Header". into this area type or paste the following

Resolution No. 12345
July 15, 2007
Page

Do *not* paste or type the page number.

You should also see a floating toolbar labelled "Header and Footer" halfway
down the screen. To insert the page number, position the cursor after the
word "Page", and then click the second button on the toolbar, which has a
"#" icon on it. This will insert the page number. It will show a different
number on subsequent pages.
 
E

edwinf

Jonathan West said:
We are getting mixed up between two quite separate things - the heading row
of a table, and the header area of a page.

If you want a separate first page header, then go to File, Page Setup, click
the Layout tab of the dialog, and check the "Different first page" checkbox.

Scroll to the first page of your document, and then go to View, Header and
Footer. The cursor should now be flashing in an area labelled "First Page
Header". Type or paste this text into the header

Republic of the Country
11th Session
Series of 2005

Scroll down to the next page, where the header area should simply be
labelled "Header". into this area type or paste the following

Resolution No. 12345
July 15, 2007
Page

Do *not* paste or type the page number.

You should also see a floating toolbar labelled "Header and Footer" halfway
down the screen. To insert the page number, position the cursor after the
word "Page", and then click the second button on the toolbar, which has a
"#" icon on it. This will insert the page number. It will show a different
number on subsequent pages.

Its easy if you are on MS Word alone, but what i need is Hot To Put It In
Code! I am a beginner on how to program the MS Word thru VB6, all i want is a
sample code regarding that matters...
 
R

Russ

Edwinf,
See below.
Its easy if you are on MS Word alone, but what i need is Hot To Put It In
Code! I am a beginner on how to program the MS Word thru VB6, all i want is a
sample code regarding that matters...
Do you have a copy of Word you can use?
You can record a macro while you do it in Word, then use ALT/F11 to go into
the VBA Editor to see what kind of code it reveals.

If you are transferring your data from another Microsoft product, this site
may be helpful:
<http://word.mvps.org/faqs/OfficeInterdev.htm>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top