macro - find object text and replace

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.

Parents
  • 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).Activate
    End Sub

Reply Children