hi. I'm trying to put together a macro that will search for an object with the label PNUMTOT and replace it with the total number of pages. any help is 'preesh.
or rather I just need to replace the selected text to the total number of pages. here is a messy attempt that does not work.
Sub pnumtots() Dim s As Shape, sr As ShapeRange Dim q$ ActiveDocument.BeginCommandGroup q = "(@type = 'text:artistic' or @type = 'text:paragraph')" Set sr = ActiveSelection.Shapes.FindShapes(Query:=q)cur = ActivePage.Index If sr.Count = 0 Then Exit Sub numPages = ActiveDocument.Pages.Count For Each p In ActiveDocument.Pages p.Activate For Each s In sr s.Text.Story.Characters.All = (numPages) Next s 'Optimization = True ActiveDocument.EndCommandGroup ActiveDocument.Pages(cur).ActivateEnd Sub
Here's an example where it walks through all the pages in the document.
On each page, it looks for only one shape named, "PAGENUMBERS".
It assumes that shape is text, and sets it to be, for example, "Page 1 of 7".
1 2 3 4 5 6 7 8 9 10 11
Sub update_my_page_numbers() Dim pageThis As Page Dim s As Shape For Each pageThis In ActiveDocument.Pages Set s = pageThis.Shapes.FindShape("PAGENUMBERS") If Not s Is Nothing Then s.Text.Story = "Page " & CStr(pageThis.Index) & " of " & CStr(ActiveDocument.Pages.Count) End If Next pageThis End Sub
Even if that's not exactly what you want to do, it might provide some clues.