Inserting page numbers in footer with word automation 
Author Message
 Inserting page numbers in footer with word automation

Can someone help me out?  I need to insert the page
number...

here's a snippet of my code

Dim oApp As Word.Application
Dim oSec As Word.Section
Dim oDoc As Word.Document

Set oApp = New Word.Application
Set oDoc = oApp.Documents.Open("c:\dir\file.doc")
With oDoc
  Set oSec = .Sections(1)
  oSec.PageSetup.DifferentFirstPageHeaderFooter = False
  oSec.Headers(wdHeaderFooterPrimary).LinkToPrevious =
False
  oSec.Headers(wdHeaderFooterPrimary).Range.Text = _
              "FREE TEXT" & Chr(10) & Chr(13) & Chr(9)
& "FREE TEXT 2"
  oSec.Footers(wdHeaderFooterPrimary).LinkToPrevious =
False
  Dim aantal
  oSec.Footers(wdHeaderFooterPrimary).Range.Text = _
              "Datum " & Date & Chr(10) & Chr(13) & "FREE
TEXT" & Chr(10) & Chr(13) & $PAGE NUMBER$
End With
oApp.Visible = True

thank you
Tim



Fri, 26 Dec 2003 22:56:41 GMT  
 Inserting page numbers in footer with word automation
Hi, Tim,

This is one way  to do it, but there are others...

Replace the lines

Quote:
>   Dim aantal
>   oSec.Footers(wdHeaderFooterPrimary).Range.Text = _
>               "Datum " & Date & Chr(10) & Chr(13) & "FREE
> TEXT" & Chr(10) & Chr(13) & $PAGE NUMBER$

with these lines:

Dim oRg As Range
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
oRg.Text = "Datum " & Date & vbCr & "FREE TEXT" & _
    vbCr & "Page "
oRg.Collapse wdCollapseEnd
oRg.Fields.Add Range:=oRg, Type:=wdFieldPage

The major item is creating a range, which enables you to tell the
.Fields.Add method where to put the page number field. Besides that, you'd
be well advised to replace all the Chr(10) & Chr(13) constructions with the
predefined constant vbCr, and replace Chr(9) with vbTab.

Regards,
Jay


Quote:
> Can someone help me out?  I need to insert the page
> number...

> here's a snippet of my code

> Dim oApp As Word.Application
> Dim oSec As Word.Section
> Dim oDoc As Word.Document

> Set oApp = New Word.Application
> Set oDoc = oApp.Documents.Open("c:\dir\file.doc")
> With oDoc
>   Set oSec = .Sections(1)
>   oSec.PageSetup.DifferentFirstPageHeaderFooter = False
>   oSec.Headers(wdHeaderFooterPrimary).LinkToPrevious =
> False
>   oSec.Headers(wdHeaderFooterPrimary).Range.Text = _
>               "FREE TEXT" & Chr(10) & Chr(13) & Chr(9)
> & "FREE TEXT 2"
>   oSec.Footers(wdHeaderFooterPrimary).LinkToPrevious =
> False
>   Dim aantal
>   oSec.Footers(wdHeaderFooterPrimary).Range.Text = _
>               "Datum " & Date & Chr(10) & Chr(13) & "FREE
> TEXT" & Chr(10) & Chr(13) & $PAGE NUMBER$
> End With
> oApp.Visible = True

> thank you
> Tim



Sat, 27 Dec 2003 01:37:36 GMT  
 Inserting page numbers in footer with word automation
tnx
Quote:
>-----Original Message-----
>Hi, Tim,

>This is one way  to do it, but there are others...

>Replace the lines

>>   Dim aantal
>>   oSec.Footers(wdHeaderFooterPrimary).Range.Text = _
>>               "Datum " & Date & Chr(10) & Chr(13)
& "FREE
>> TEXT" & Chr(10) & Chr(13) & $PAGE NUMBER$

>with these lines:

>Dim oRg As Range
>Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
>oRg.Text = "Datum " & Date & vbCr & "FREE TEXT" & _
>    vbCr & "Page "
>oRg.Collapse wdCollapseEnd
>oRg.Fields.Add Range:=oRg, Type:=wdFieldPage

>The major item is creating a range, which enables you to
tell the
>..Fields.Add method where to put the page number field.
Besides that, you'd
>be well advised to replace all the Chr(10) & Chr(13)

constructions with the

- Show quoted text -

Quote:
>predefined constant vbCr, and replace Chr(9) with vbTab.

>Regards,
>Jay



>> Can someone help me out?  I need to insert the page
>> number...

>> here's a snippet of my code

>> Dim oApp As Word.Application
>> Dim oSec As Word.Section
>> Dim oDoc As Word.Document

>> Set oApp = New Word.Application
>> Set oDoc = oApp.Documents.Open("c:\dir\file.doc")
>> With oDoc
>>   Set oSec = .Sections(1)
>>   oSec.PageSetup.DifferentFirstPageHeaderFooter = False
>>   oSec.Headers(wdHeaderFooterPrimary).LinkToPrevious =
>> False
>>   oSec.Headers(wdHeaderFooterPrimary).Range.Text = _
>>               "FREE TEXT" & Chr(10) & Chr(13) & Chr(9)
>> & "FREE TEXT 2"
>>   oSec.Footers(wdHeaderFooterPrimary).LinkToPrevious =
>> False
>>   Dim aantal
>>   oSec.Footers(wdHeaderFooterPrimary).Range.Text = _
>>               "Datum " & Date & Chr(10) & Chr(13)
& "FREE
>> TEXT" & Chr(10) & Chr(13) & $PAGE NUMBER$
>> End With
>> oApp.Visible = True

>> thank you
>> Tim

>.



Sat, 27 Dec 2003 21:07:48 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Word not printing total number of pages in page footer correctly

2. Adding Total Number of slides to the page number field in the footer

3. Insert a random number number into a pre-designed Word doc

4. Putting page numbers: 1 of xx in the footer

5. Page Numbering in Footer

6. HIGHEDIT & RTF page numbers in footer

7. PC DOCS doc number footer for Word 97

8. Create a Page Footer in a Word Document

9. Table Footer/ Page Footer

10. Page footer and Group footer

11. Page Footer on Page 1 Refers to Page 2

12. Insert information into a word document using automation

 

 
Powered by phpBB® Forum Software