Keep with Next if Colon at End of Paragraph

You may want any paragraph that ends with a colon to always be on the same page as the next paragraph. You can handle this by manually applying Keep with next to all such paragraphs. However, there is an easier way. Via this article, you can access a macro that does the work for you – it applies Keep with next to all paragraphs in the active document that end with a colon.

About the Keep with next option

In the Paragraph dialog box, on the Line and Page Breaks tab, you will find some options that can be used to tell Word how to paginate your document.

The Keep with next option in the Paragraph dialog box

If you turn on the Keep with next option for a paragraph, Word will force that paragraph to always follow the next paragraph – the two paragraphs will be on the same page. This is normally what you want to happen for a heading and the following paragraph. In general, a heading should not be the last paragraph on a page – it should always be followed by at least one paragraph. Thus, if the paragraph after a heading moves to the next page, you want the heading to automatically follow. You can manage this easily by making sure that all heading styles have been defined with Keep with next turned on.

However, there are other situations where Keep with next is relevant and where the style in use should not have Keep with next turned on in general. For example, this may be the case for paragraphs that end with a colon.

Macro solution

Via the link below, you can view or download a macro that iterates through all paragraphs in the active document. If a colon is found immediately before the paragraph mark or, in case of a table, before the end of cell marker, the Keep with next option is turned on for that paragraph. A message will appear when finished, telling how many colons were found.

How to get the macro

Click the link below to open a window with the macro code:

Related information

See About VBA Macros and Code Snippets and How to Install a Macro for misc. information that may help you in your work with macros and for information about how to install macros.