{"id":25603,"date":"2022-11-12T16:51:49","date_gmt":"2022-11-12T16:51:49","guid":{"rendered":"https:\/\/jurn.link\/jurnsearch\/?p=25603"},"modified":"2023-12-03T16:52:40","modified_gmt":"2023-12-03T16:52:40","slug":"word-macro-to-increment-the-numbers-in-a-back-of-the-book-index","status":"publish","type":"post","link":"https:\/\/jurn.link\/jurnsearch\/index.php\/2022\/11\/12\/word-macro-to-increment-the-numbers-in-a-back-of-the-book-index\/","title":{"rendered":"Word macro to increment the numbers in a back-of-the-book index"},"content":{"rendered":"<p>Situation: You have a completed back-of-the-book index for a book, perhaps created with PDF Index Generator. You are then required to add a further page to the book, that you thought was finished. Such a change will \u2018throw off\u2019 most of the numbers in the index, but not all of them. Only the page-numbers after the point where the new page was added. Do you need to remake the index again? No.<\/p>\n<p>Solution: You use the following Microsoft Word macro to do the required \u2018intelligent corrections\u2019 of the changed numbers in the Index.<\/p>\n<p>Use: Copy-paste the kaput Index to a new Word document of the same page size, with retained formatting. Edit the macro\u2019s three variable numbers for your needs and load it. Run it. Copy back the results to the book. Check the new index aligns with the book.<\/p>\n<p>Change the numbers indicated. The first number is the increment, and the other is the page number above which incrementing is done.<\/p>\n<p><code>' WORD MACRO - Increment the numbers in the back-of-a-book index by x, only if above a certain number.<br \/>\nSub Demo()<br \/>\nApplication.ScreenUpdating = False<br \/>\n' Change the following number 1 to the increment you need. Number of pages added = the number you need.<br \/>\nConst i As Long = 1<br \/>\nWith ActiveDocument.Range<br \/>\n  With .Find<br \/>\n    .ClearFormatting<br \/>\n    .Text = \"<[0-9]{2,3}>\"<br \/>\n    .Replacement.Text = \"\"<br \/>\n    .Forward = True<br \/>\n    .Wrap = wdFindStop<br \/>\n    .MatchWildcards = True<br \/>\n    .Execute<br \/>\n  End With<br \/>\n  Do While .Find.Found<br \/>\n  ' Change the next number to the page-number below which all must stay the same.<br \/>\n    If CLng(.Text) > 77 Then<br \/>\n\t  ' Page number 2000 is the ending backstop number - change this only if you have a monster book.<br \/>\n      If CLng(.Text) < 2000 Then .Text = CLng(.Text) + i\n    End If\n    .Collapse wdCollapseEnd\n    .Find.Execute\n  Loop\nEnd With\nApplication.ScreenUpdating = True\nEnd Sub\nChange the numbers to suit your situation.<\/code><\/p>\n<p>Here the above macro is set to increment by 1, any page-number it finds in the index. But only if it has a value between 77 and 2000. You are assumed to have added one new page at page 76. Any indexed page number for page 77 must therefore now become 78, and so on. Numbers are recognised individually, even if in the hyphenated form, e.g.: 99-100 or similar.<\/p>\n<p>Your index is assumed to have no dates or street numbers used as index terms, e.g. \u201c1066 A.D., Battle of Hastings, p. 356\u201d, or \u201c221B Baker Street, p. 73\u201d.<\/p>\n<p>The newly added page(s) will of course need to have their new entries indexed, if not simply illustrations, and manually added to the revised index.<\/p>\n<p>So far as I can tell, there\u2019s no way to do this with a regex.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Situation: You have a completed back-of-the-book index for a book, perhaps created with PDF Index Generator. You are then required &hellip;<\/p>\n<p><a href=\"https:\/\/jurn.link\/jurnsearch\/index.php\/2022\/11\/12\/word-macro-to-increment-the-numbers-in-a-back-of-the-book-index\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-25603","post","type-post","status-publish","format-standard","hentry","category-jurn-tips-and-tricks"],"_links":{"self":[{"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/posts\/25603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/comments?post=25603"}],"version-history":[{"count":1,"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/posts\/25603\/revisions"}],"predecessor-version":[{"id":25604,"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/posts\/25603\/revisions\/25604"}],"wp:attachment":[{"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/media?parent=25603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/categories?post=25603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jurn.link\/jurnsearch\/index.php\/wp-json\/wp\/v2\/tags?post=25603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}