murfeezlaw
Programmer
I could really use some help here. I'm using VBA in Access to open Word and dynamically create a document. At the end of this document I need to insert more documents. That is working fine. My problem is with the page numbers in the footers. The documents being inserted all have page numbers in the document. I programmatically added a section break after each of the documents being inserted but the code in the footers is as follows: Page { PAGE \*MERGEFORMAT } of {NUMPAGES \*MERGEFORMAT} I need it to count sections not pages
i think i need to programatically change the code at the end of all these documents. i tried this code...
Dim s As Section
Dim f As Field
Dim fcode As Range
For Each s In ActiveDocument.Sections
With s.Headers(wdHeaderFooterPrimary).PageNumbers
.RestartNumberingAtSection = True
.StartingNumber = 1
End With
With s.Footers(wdHeaderFooterPrimary).Range
For Each f In .Fields
If f.Type = wdFieldNumPages Then
Set fcode = f.Code
fcode.Text = "SECTIONPAGES"
End If
Next f
.Fields.Update
End With
Next s
But I get the Method or data member not found error. When i inserted the code in a macro in Word it ran fine. I was just wondering if i was missing a Reference or what could cause that error.
i also tried...
For J = 1 To ActiveDocument.Sections.Count
For K = 1 To ActiveDocument.Sections(J).Headers.Count
objWord.ActiveDocument.Sections(J).Headers(K).PageNumbers.RestartNumberingAtSection = True
objWord.ActiveDocument.Sections(J).Headers(K).PageNumbers.StartingNumber = 1
Next K
For K = 1 To ActiveDocument.Sections(J).Footers.Count
If Field.Type = wdFieldNumPages Then
Set fcode = f.Code
fcode.Text = "SECTIONPAGES"
End If
.Fields.Update
Next K
Next J
but only the first part worked. does anyone have any ideas on this? i've been working on this forever. i'd really appreciate some ideas. With section breaks i need the page numbers to read Page x of y, starting at Page 1 on each new page.
TIA
Ted
i think i need to programatically change the code at the end of all these documents. i tried this code...
Dim s As Section
Dim f As Field
Dim fcode As Range
For Each s In ActiveDocument.Sections
With s.Headers(wdHeaderFooterPrimary).PageNumbers
.RestartNumberingAtSection = True
.StartingNumber = 1
End With
With s.Footers(wdHeaderFooterPrimary).Range
For Each f In .Fields
If f.Type = wdFieldNumPages Then
Set fcode = f.Code
fcode.Text = "SECTIONPAGES"
End If
Next f
.Fields.Update
End With
Next s
But I get the Method or data member not found error. When i inserted the code in a macro in Word it ran fine. I was just wondering if i was missing a Reference or what could cause that error.
i also tried...
For J = 1 To ActiveDocument.Sections.Count
For K = 1 To ActiveDocument.Sections(J).Headers.Count
objWord.ActiveDocument.Sections(J).Headers(K).PageNumbers.RestartNumberingAtSection = True
objWord.ActiveDocument.Sections(J).Headers(K).PageNumbers.StartingNumber = 1
Next K
For K = 1 To ActiveDocument.Sections(J).Footers.Count
If Field.Type = wdFieldNumPages Then
Set fcode = f.Code
fcode.Text = "SECTIONPAGES"
End If
.Fields.Update
Next K
Next J
but only the first part worked. does anyone have any ideas on this? i've been working on this forever. i'd really appreciate some ideas. With section breaks i need the page numbers to read Page x of y, starting at Page 1 on each new page.
TIA
Ted