word report add page number and change text font

hi guys,
im generating a word report, what i need is to put the page number and a small text on each page footer, can this be done. like the text on the left and the page number on the left.
and i need to change the font of a specific section or text in the report, is that dooable?
thanks
LVL 3
mte01Asked:
Who is Participating?
 
omegaomegaDeveloperCommented:
Hello, mte01,

Yes.  For the three items that you mention you could do something like:

        Dim docNew As New Word.Document
        docNew.Sections.Item(1).Footers.Item(1).Range.Text = "Here is some footer text"
        docNew.Sections.Item(1).Footers.Item(1).PageNumbers.Add(PageNumberAlignment:=0)
        docNew.Range.Text = "Here is some text, in which the font of the third word will be changed."
        docNew.Words.Item(3).Font.Name = "Courier New"
        docNew.Words.Item(3).Font.Size = 16

Cheers,
Randy

0
 
mte01Author Commented:
hi, thanks for the help it's working but i just to need to set the location of these things, i need them to be something like that:

          bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
          bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
          bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla



Here is some footer text                                                                                                      page 1 of 1


what i meant is to have the text on the left and the page number on the right section of the document.
thanks again for the help
0
 
omegaomegaDeveloperCommented:
Hello, mte01,

There are many possible ways to do this.  Typically the footer defaults to having a center-tab in the middle and a right-tab on the right.  If this is the case for your report, then you could do this:

        Const wdFieldNumPages As Integer = 26
        Const wdFieldPage As Integer = 33

        Dim docNew As New Word.Document
        Dim rngFooter As Word.Range
        rngFooter = docNew.Sections.Item(1).Footers.Item(1).Range

        rngFooter.Fields.Add(Range:=rngFooter, Type:=wdFieldNumPages)
        rngFooter.Collapse()
        rngFooter.Text = " of "
        rngFooter.Collapse()
        rngFooter.Fields.Add(Range:=rngFooter, Type:=wdFieldPage)
        rngFooter.Collapse()
        rngFooter.Text = "Here is some Text" & vbTab & vbTab & "Page "

If the tabstops in the footer are different than normal you would need to modify them before using the above (or modify the above as necessary).

Cheers,
Randy
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
mte01Author Commented:
thanks for the help, it's working now,
do u have a tutorial on how to build word document and things like that? coz i cant find any
0
 
omegaomegaDeveloperCommented:
Hello, mte01,

No, I'm sorry I don't have a good reference for this.  I don't normally do a lot of work with Word.

A general technique that I have often found helpful is to record a Word macro while I manually perform the steps required.  The VBA in the macro produced is typically not directly useful, but can give some good clues about the properties and methods that can be used.  

Cheers,
Randy
0
 
mte01Author Commented:
>>omegaomega

Can you please provide help in this: http:Q_21837643.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.