murfeezlaw
Programmer
I'm using an Access application to create a document(A) and insert many word documents(B) into it.
Is there a way to count the pages of the document being inserted? And if it's an odd number of pages to add a blank page? If i just do a page count of the document in VBA it'll count the pages of document A. I need it to count the pages in the document being inserted.
i tried...
objWord.Selection.InsertBreak Type:=wdSectionBreakOddPage
which worked great but i had to run some code at the end to fix the pages in the footers which defeated the purpose of the break on odd pages.
Dim s As Word.Section
Dim f As Word.Field
Dim fcode As Word.Range
For Each s In objWord.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
With s.Footers(wdHeaderFooterFirstPage).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
Any ideas? Thanks guys
Ted
Is there a way to count the pages of the document being inserted? And if it's an odd number of pages to add a blank page? If i just do a page count of the document in VBA it'll count the pages of document A. I need it to count the pages in the document being inserted.
i tried...
objWord.Selection.InsertBreak Type:=wdSectionBreakOddPage
which worked great but i had to run some code at the end to fix the pages in the footers which defeated the purpose of the break on odd pages.
Dim s As Word.Section
Dim f As Word.Field
Dim fcode As Word.Range
For Each s In objWord.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
With s.Footers(wdHeaderFooterFirstPage).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
Any ideas? Thanks guys
Ted