Skip to main content
Participant
February 25, 2026
Answered

How to Find/Replace text in a specific range of pages?

  • February 25, 2026
  • 5 replies
  • 149 views

Hi there,

Looking to Find/Replace text limited to a specific range of pages, such as changing text on pages 112-116 of a 200 page document. Mindful that this is really necessary functionality, but can’t seem to find it anywhere! Can’t use any scripts/plugins either.

Thanks in advance!

    Correct answer Mike Witherell

    Find/Change can search by the document, or the story, or the selection. Maybe pre-select the text between pages 112 to 116 and then run the search.

    5 replies

    Participant
    February 26, 2026

    Fantastic, thanks ​@Mike Witherell ​@Eugene Tyson  ​@rob day for your responses, all incredibly helpful. Was trying to avoid scripts as I’m preparing a document that a client will need to update in a similar fashion, and wanted to minimise the complexity for someone not familiar with InDesign. Looks like it’s unavoidable, no harm done. Thanks!

    rob day
    Community Expert
    Community Expert
    February 26, 2026

    Mindful that this is really necessary functionality  … Can’t use any scripts/plugins either.

     

    Hi ​@callum_6285 , You would need a script—is there a reason you can’t use one? 

    Community Expert
    February 26, 2026

    The only other way I can think of is to lock the text frames on the pages where the changes aren’t needed. but that’s very time consuming. 

    I missed the part about not being able to use scripts - not sure why… but fairs fair, missed that part somehow. 

    Mike Witherell
    Community Expert
    Community Expert
    February 26, 2026

    Hey Eugene,

    Yes, if the text is separate stories on pages 112-116, as the OP describes, then the person could insert a Type tool in the text on each of those 5 pages, choosing to search Story each time.

    Your script idea sounds interesting! I will look for an opportunity to test it. I’m not sure why the OP states that they cannot use a script.

    Mike Witherell
    Community Expert
    February 27, 2026

    Thanks! Please do. If it can be improved I’d love to see it. Page Range for the find dialog seems like a logical move. But it’s something I’ve rarely come up against.

    Community Expert
    February 26, 2026

    @Mike Witherell fantastic idea when all the text frames are threaded and you can select from page to page, but InDesign doesn’t allow to split selection so you can’t select page 2, 12, 112 etc. 

    This script is rudimentary but might work for you - I urge you to test it on a sample document. There  are much better scripters than me on here so maybe one will be happy to make it even better. 

    But literally the best I can get right now 

     

    // Global Script - No #target directive

    var doc = app.documents.length ? app.activeDocument : null;
    if (!doc) { alert("No document open."); exit(); }

    // ------------------
    // Build Dialog
    // ------------------
    var w = new Window("dialog", "Find / Change by Page Range");
    w.orientation = "column"; w.alignChildren = "left";

    w.add("statictext", undefined, "Page range (e.g., 1-5, 8, A-3):");
    var pageInput = w.add("edittext", undefined, doc.pages[0].name + "-" + doc.pages[doc.pages.length - 1].name);
    pageInput.characters = 25;

    w.add("statictext", undefined, "Find what:");
    var findInput = w.add("edittext", undefined, "");
    findInput.characters = 30;

    w.add("statictext", undefined, "Replace with:");
    var changeInput = w.add("edittext", undefined, "");
    changeInput.characters = 30;

    var modeGroup = w.add("panel", undefined, "Search Type");
    modeGroup.orientation = "row";
    var textRadio = modeGroup.add("radiobutton", undefined, "Text");
    var grepRadio = modeGroup.add("radiobutton", undefined, "GREP");
    textRadio.value = true;

    var optPanel = w.add("panel", undefined, "Options");
    optPanel.orientation = "column"; optPanel.alignChildren = "left";
    var caseCheck = optPanel.add("checkbox", undefined, "Case Sensitive");

    var btnGroup = w.add("group");
    btnGroup.add("button", undefined, "OK");
    btnGroup.add("button", undefined, "Cancel");

    if (w.show() !== 1) exit();

    // ------------------
    // Page Logic
    // ------------------
    var pagesToSearch = [];
    var parts = pageInput.text.replace(/\s/g, "").split(",");
    for (var i = 0; i < parts.length; i++) {
    var range = parts[i].split("-");
    var start = doc.pages.itemByName(range[0]);
    var end = doc.pages.itemByName(range.length > 1 ? range[1] : range[0]);
    if (start.isValid && end.isValid) {
    for (var p = start.documentOffset; p <= end.documentOffset; p++) pagesToSearch.push(doc.pages[p]);
    }
    }

    // ------------------
    // Execute Search
    // ------------------
    var totalChanges = 0;
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;

    for (var k = 0; k < pagesToSearch.length; k++) {
    var frames = pagesToSearch[k].textFrames;
    for (var f = 0; f < frames.length; f++) {
    var story = frames[f].parentStory;

    if (textRadio.value) {
    // Literal Text replacement
    var match;
    app.findGrepPreferences.findWhat = escapeGrep(findInput.text);
    var results = story.findGrep();

    // Loop backwards to keep index integrity
    for (var r = results.length - 1; r >= 0; r--) {
    // Check Case Sensitivity
    if (!caseCheck.value || results[r].contents === findInput.text) {
    results[r].contents = changeInput.text;
    totalChanges++;
    }
    }
    } else {
    // GREP replacement
    app.findGrepPreferences.findWhat = caseCheck.value ? findInput.text : "(?i)" + findInput.text;
    app.changeGrepPreferences.changeTo = changeInput.text;
    totalChanges += story.changeGrep().length;
    }
    }
    }

    // Cleanup
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;

    alert("Done! Total changes: " + totalChanges);

    function escapeGrep(str) {
    return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
    }

     

    Mike Witherell
    Community Expert
    Mike WitherellCommunity ExpertCorrect answer
    Community Expert
    February 26, 2026

    Find/Change can search by the document, or the story, or the selection. Maybe pre-select the text between pages 112 to 116 and then run the search.

    Mike Witherell