Is there a way to get the page number to be the number of the entire report and not just the page number of that tab. I.E. If you have 9 tabs and each one is a page long, can you get the page numbers to show up as 1,2,3,4,5,6,7,8,9, instead of 1,1,1,1,1…?
The only way I ever “got around” this was when I knew my first three tab were one page summaries… so I could just add the number of pages to the detail tab.
Come to think of it, though, there might be a VBA solution…
A VBA solution can be made but it can be cumbersome and I am not sure how many would like it. But here goes nothin…
Create a variable on every Tab, Call it PgTab1, 2 [=Page()] and use it instead of Page() function in all your reports.
Add the following macro to the report and run it. It will populate the report page numbers. It is recommended that you refresh the report within the macro to get the fresh number of pages.
Sub NumberRep()
ActiveDocument.Refresh
PageNum = 0
For i = 2 To ActiveDocument.Reports.Count
PageNum = PageNum + ActiveDocument.Reports(i - 1).NumberOfPages
DocumentVariables.Item("PgTab" & i).Formula = "= Page() + " & PageNum
ActiveReport.ForceCompute
Next i
End Sub
Kindly post if you see any problems or have any ideas for improvements…
Ok, I used avaksi’s solution and modified it so it is dynamic. First I created a variable for each tab that is named exactly the same as the tab name. Then I used this code:
Sub PageNumberTabs()
PageNum = 0
For i = 1 To ActiveDocument.Reports.Count
If i <> 1 Then
DocumentVariables.Item(ActiveDocument.Reports.Item(i).Name).Formula = "= " & Chr(34) & "Page " & Chr(34) & " & FormatNumber (Page() + " & PageNum & ", ""#"")"
Else
DocumentVariables.Item(ActiveDocument.Reports.Item(i).Name).Formula = "= " & Chr(34) & "Page " & Chr(34) & " & FormatNumber (Page() , ""#"")"
End If
ActiveReport.ForceCompute
PageNum = PageNum + ActiveDocument.Reports(i).NumberOfPages
Next i
End Sub
I will have this called from the afterrefresh() event. I tested it and it numbers all the tabs correctly. Even if you move the tabs around, there is no code changes that have to occur. I will probably make this an addin for some other reports.
NEO,
Are you sure, you are calling the macro in after_refresh event.
The code will assign the value to the variables after refresh, for those variables which you said created same as tab names.
I would suggest assign zero(0) OR “”(double quotes) to the variables depending on the return type and try.
I created four tabs, as 1998, 1999, 2000 and All. Created four varibles named same as the Tabs
1998=Page()
1999=Page()
2000=Page()
All=Page()
VB editor (Alt F11), I wrote this code
Private Sub Document_AfterRefresh()
Call PageNumberTabs
End Sub
Sub PageNumberTabs()
PageNum = 0
For i = 1 To ActiveDocument.Reports.Count
If i <> 1 Then
DocumentVariables.Item(ActiveDocument.Reports.Item(i).Name).Formula = "= " & Chr(34) & "Page " & Chr(34) & " & FormatNumber (Page() + " & PageNum & ", ""#"")"
Else
DocumentVariables.Item(ActiveDocument.Reports.Item(i).Name).Formula = "= " & Chr(34) & "Page " & Chr(34) & " & FormatNumber (Page() , ""#"")"
End If
ActiveReport.ForceCompute
PageNum = PageNum + ActiveDocument.Reports(i).NumberOfPages
Next i
End Sub
This solution worked wonderfully. Thanks!
Can anyone suggest how to get the Page 1 of Page N in the same situation. Right now, its generating Page 1 to N , but i dont know how to get the total number of pages count and show it in all the reports.
I did try that. But my last report has multiple sheets. eg. my last report has pages 18, 19 and 20
And this one gives me 18 as the total pages and not 20
You probably don’t need this answer anymore, but for anyone else with the same question, you can add a line of code to the macro and it will insert the total number of pages into another variable. I called mine LastPage. Then you will just need to add & "of " & to your formulas and all will be fine.
Sub PageNumberTabs()
…(same code as posted earlier)…
PageNum = PageNum + ActiveDocument.Reports(i).NumberOfPages
Next i
'The following line is the one I added
DocumentVariables.Item("LastPage").Formula = PageNum
I’ve added your amendment to get the “page x of y” but it doesn’t seem to give me the right numbers.
I have a 3 tab, 13 page report
Tab 1 -Notes - 1 page
Tab 2 -Directorate - 2 pages
Tab 3 -Buyer - 9 pages
The pages sequentially number perfectly (thanks) although the final part giving the total number of pages is having problems.
i.e the second tab numbers, Page 2 of 4, Page 5 of 5… the thrid tab also has problems.
I have the VB as you have above, I created variables just like you did in your sample report and I have done the page numbers as you suggest.