page numbering macro causes crash...

Hi.  I have this code and it runs okay as long as I don't have too many pages with graphics on them.  I can re-create the crash many times and would like to know if there is something else I can add to this so that the crash does not happen.  Maybe something that will check when the page deletion process is taking longer than normal and the macro will pause to allow processing?

Dim s As Shape

    For Each pageThis In ActiveDocument.Pages
        Set sPageNumThis = pageThis.Shapes.FindShape("pagetotal")
        If Not sPageNumThis Is Nothing Then
            sPageNumThis.Text.Story = CStr(ActiveDocument.Pages.Count)
        End If
    Next pageThis

Parents Reply
  • that helps...not sure why I need to do that now since it ran fine before I inserted the new code.

    Did you have "Option Explicit" in your code module before adding the new code?

    having an issue and not sure how this new setup runs and does not run when I don't need it to.

    I copied the code from your post, then pasted it into modules in a project in 2019. It works the way that I would expect it to.

    When I add or remove a page, it runs the Update sub.

    If I run the set_suppress_renumber_false sub, then adding or removing a page does not run the Update sub.

    If I run the set_suppress_renumber_true sub, then adding or removing a page, again, runs the Update sub.

    If you need more tools for figuring out what is going on, you might look at:

    • setting breakpoints in one or more subs
    • single-stepping through the execution of code (e.g., after hitting a breakpoint) using Debug>Step Into
    • using the Locals window in the VBA editing environment to see what is going on while single-stepping through the code
Children