• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

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
0
mte01
Asked:
mte01
  • 3
  • 3
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now