1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| Public Sub Paginate(Pages As DpVBAInterface)
Dim DocObj As busobj.Document 'Document Object
Dim RepObj As busobj.Report 'Report Object
Dim SecArray 'Array that will hold section values
Dim IntSecArrayLen As Integer 'Length of the section array
Dim SectionType As String 'Data Type of Section
Dim i As Integer
'Dim PagesArray(1, 2)
Set DocObj = ActiveDocument ' Get the Active Document
Set RepObj = ActiveReport ' Get the Selected Report
Set SectionPage = DocumentVariables
' Retrieve name of the top level section (We can also know if there exist any sub-sections)
SectionName = RepObj.GeneralSectionStructure.SubSectionStructure.Master.Name
' Retrieve values of the Section
SecArray = DocObj.DocumentVariables(SectionName).Values(boUniqueValues)
SectionType = TypeName(SecArray(1)) ' Identify Data type of the section
IntSecArrayLen = UBound(SecArray)
Pages.UserString(1) = "PageCount"
'Pages.DpVBACubes.SetNbCubes (1)
'Our new cube is the first one
Dim PageCount As DpVBACube
Set PageCount = Pages.DpVBACubes.Item(1)
PageCount.DpVBAColumns.SetNbColumns (2)
PageCount.DpVBAColumns.Item(1).Name = "Contract Number"
PageCount.DpVBAColumns.Item(2).Name = "Total Pages in Section"
PageCount.DpVBAColumns.NbLines = IntSecArrayLen 'Number of Lines = number of contract Sections
Dim ContractNumber As DpVBAColumn
Dim PagesInSection As DpVBAColumn
Set ContractNumber = PageCount.DpVBAColumns.Item(1)
ContractNumber.Qualification = boDimension
ContractNumber.Type = boCharacterObject
For i = 1 To IntSecArrayLen
ContractNumber.Item(i) = SecArray(i)
Next i
Set PagesInSection = PageCount.DpVBAColumns.Item(2)
PagesInSection.Qualification = boDimension
PagesInSection.Type = boCharacterObject
With RepObj
For i = 1 To IntSecArrayLen
'Filters the report by contract number
.AddComplexFilter SectionName, "=<" & SectionName & "> = """ & SecArray(i) & """"
.ForceCompute
'Assigns the page number to the array
PagesInSection.Item(i) = .NumberOfPages
'Releases the filter
.AddComplexFilter SectionName, "=(0=0)"
.ForceCompute
Next i
End With
End Sub |
Partager