We create a new paragraph at the end of the current heading. This macro is nice for appending ideas in novel notes or editing in working manuscript outlines.
Thanks for your interest
This content is part of a paid plan.
Insert a new empty paragraph below heading
We introduce another macro in the series of small, but useful, editing tools. We create a macro that inserts a new empty paragraph at the end of the current heading for any standard Word heading style.
Huh? Isn't that what the Return key is for?
Yeah, but as with the other variations, we're streamlining the process. The idea is to create the paragraph at the end regardless of where you are in the heading content, so you can just start typing.
![Example of adding a new paragraph at the end of the current heading](https://cdn.prod.website-files.com/646fc06a34fb2c617f8a761a/650b7f5c6cb4d80464431550_New-Empty-Paragraph-Below-Heading-Example-1.gif)
At least approaches exist to accomplish this task. We’ll take the easier, more standard way in this article. The more general, slightly harder, method in the member version further works for derived heading styles. This macro is also a variation of a previous quick editing macro that inserts a new empty paragraph above or below the current one.
What are the manual steps?
Thinking about the manual steps required to accomplish the task gets us started with the macro, but it also puts into perspective how many steps we're actually saving on each use. What does our macro need to accomplish?
- Move to the end of the last paragraph of the heading content (slow)
- Press the Return key
- Change the paragraph style (if needed)
Step 1 is the slowest part. We can use the GoTo dialog using F5 or Control+G in Windows (or Command+Option+G on a Mac). It's also accessible under the Home ribbon tab via Find → GoTo…, but even with the shortcut, it's still clunky and slow in my opinion. Unless you're moving a large distance in the document, it's no faster than just grabbing the mouse and clicking in the document or the Navigation Pane.
We have a separate macro article to jump to a nearby heading, so that would be speed up step 1 significantly, but why not just tap Command+Control+Option+Return (my assigned shortcut)? Done. Start typing.
Keep in mind, the exact steps in VBA are often a little different (better or easier?) since VBA has access to the document internals. It does not need to interact with the document through the screen, keyboard, and mouse like we do.
Create the empty macro
A previous post covers using the macro dialog to create an empty macro like the one shown below:
VBA ignores the text after a single quote as a comment meant for only human readers. Our macro steps begin on the empty line below it.
Understanding common VBA object thingys
We work in Word interacting with the application and content using the keyboard and mouse. VBA represents the document elements internally mimicking our concept of document structure.
Each "object" representation acts like a data "type". A Paragraph is different than a Document which is different from a Shape. Each type consists internally of various data (called "properties") and actions (called "methods") which we use to manipulate the associated document content. Generally, speaking the VBA representations use the same name with a capital letter, so a paragraph is what we see on the screen, but a Paragraph is VBAs internal representation of it.
What is the Selection?
A selection (with a lowercase s) is what we see on the screen when we use the mouse or keyboard to select some document content. Roughly speaking, a selection spans a contiguous range of document content. We will ignore non-contiguous or block selections for all macros since VBA does not understand them well.
VBA represents the on-screen selection with an object called the Selection (with a capital S), but VBA also considers a simple insertion point (the blinking I-bar waiting for you to type) to be an empty Selection. The Selection is a special document range, but only one Selection exists per document. The Selection has many methods we use to control its position, its extent in the document, deleting the content, and more.
What is a Paragraph?
A paragraph is the content we see on the screen bounded by (usually invisible) paragraph markers.
In VBA, it's conceptually the same thing, a range of document content that ends with a paragraph marker, but a VBA Paragraph includes some extra properties like the current Style or OutlineLevel as well as some methods specialized for manipulating paragraphs like indenting the text or outline promotion or demotion.
New paragraph below a standard heading
This version applies to standard Word heading styles Heading 1 – 9 based on the behavior of the standard GoTo methods of the Selection object. We use the GoToNext method. We also used the GoTo methods for heading navigation in a previous article.
We need to specify what kind of document element we wish to jump to it. This uses the What option along with a constant from the table of possible GoTo items.
The obvious constant for this macro is wdGoToHeading for headings. We assign the heading value to the What option using a colon equals := symbol (regular variable assignments just use an equals = sign).
Now, the insertion point is located at the next heading just below where we want our new paragraph.
Call a previous macro to finish
Now we can “call” an old macro we previously created to insert a new paragraph the above current heading paragraph (see the previous article).
We insert it above the current position in the document because the next heading is below the end of the previous heading content.
That's it. We're done.
Uhhh …
What. Did. We just do?
Did you feel the electricity crackle through the air? Like VBA lightning or the Flash ran through the room. Whoosh and gone.
We just used a macro within a macro. Given our position based on the initial heading jump, we took advantage of the other macro without having to reinvent the wheel to get it done (we do that below also, if you're sad about it). Just include both macros in your VBA editor (placement doesn't matter), and the old one should automatically be used when the main macro "calls" it.
Technically we don't need to use the keyword "Call" in this case, but it seems clearer since this is the first time (assuming you're following along with the articles) we've called a different macro from within another.
This technique is a foundation of programming, break down bigger tasks into smaller bite-sized pieces. It's not quite as eminently useful in Word VBA editing macros because most of our editing tasks are smaller and more targeted, but it does give us a new tool to create some more complex and interesting macros. We do not need to repeatedly solve the same small problems in our bigger macros.
Any gotchas?
This macro is relatively simple and probably safe, but what are some potential problems?
In full disclosure, the solutions to the relatively small problems are a little more technical than they appear at first glance (not bad just more than desired for this beginner-level macro), so we will defer them to the big sibling member content.
What if no later headings exist?
Another way to ask this question is did we move when we attempted to jump to the next heading?
Turns out the macro doesn't work as expected when no more headings exist in the document. When Word cannot find another heading below the current one, the insertion point will not move.
With the GoToNext method, a missing heading only results in a logical error (as opposed to one that crashes the macro) where the new empty paragraph is placed in the wrong location below the current paragraph.
We could just stop the macro and not insert the misplaced paragraph, but we would need a way to detect the lack of movement and then make the corresponding decision. The solution is slightly more technical than it appears since we need to store the initial position and then make a comparison to decide whether to add the new paragraph or not. We can fix it in the simple version, but it gets more programmy quick which I try to avoid in beginner articles.
As written then, if no later headings exist, the macro will just insert a paragraph below the current one. While not the most intuitive outcome, it is okay. The member version will default instead to adding a new empty paragraph the end of the document which seems to be a more intuitive backup result.
What about the end of the document?
What happens if we run the macro at the end of the document?
I suspect few people even considered this special case because it is not an obvious problem. In principle, the macro should just add an empty paragraph at the end of the document. However, this case is actually a more subtle problem than it appears.
Spanning the heading and its content compared to the whole document happens differently when involving the end of document paragraph marker. We would need to detect the difference to make the correct choice. The same issue also affects the final position of the insertion point, so we further need to correct for that aspect. As a result, we will also not tackle this uncommon problem here.
Initial simple macro using another macro
Now we just put the two commands together, and our macro is complete.
This macro works for standard Word heading styles Heading 1 – 9. I assigned this one to Command+Control+Option+Return in Word for Mac and Control+Win+Alt+Return in Windows (see another article for how we can assign the latter since the Win key cannot normally be used for shortcuts in Word for Windows). The extended content below works the same as this one, but it does not require a separate macro.
Revised simple macro
If you prefer to not rely on a previous macro, we can accomplish the same job in a different way. When working with or around headings and their associated content, Word VBA isn't as nice compared to other features it offers, but we can get the main job done without much trouble.
Move backward one paragraph
At this point in the macro, we've just jumped to the next heading in the document. We could just insert a paragraph before the current one, but it would inherit a heading style because that is the style of the current paragraph.
Ughhh. Maybe not wrong, but it's annoying.
We can avoid this simply by moving back to the previous paragraph, so the new paragraph inherit its style which is much more likely to be the correct one. How?
Before adding a paragraph, we instead move back one character just inside the previous paragraph using the MoveLeft method.
The default step size is by a single character which is exactly what we want, so no additional options are needed.
Another way to handle this wrong-paragraph-style quirk is to just assign the desired style at the end, but this manual workaround avoids having to do that. See the member article if you would prefer that approach.
Insert the new paragraph
Then we can insert the paragraph after this one using the InsertParagraphAfter method.
We do not need to refer to the Paragraphs collection in any way to insert the new empty paragraph since the Selection already conveniently has the above method.
Move to the new empty paragraph
We need to collapse the Selection using the Collapse method since it will automatically expand to include the new paragraph marker.
It collapses toward the beginning of the Selection by default. We need it to collapse toward the end of the Selection, so we add the Direction option.
The wdCollapseEnd constant is in a very short table of Word constants.
Final revised simple macro
For those that prefer to not use a separate macro to accomplish this simple task, we can replace the macro call in the earlier version with the above commands.
I assigned my version of this macro to Command+Control+Option+Return in Word for Mac and Control+Win+Alt+Return in Windows. See another article for how we can assign the latter as a workaround since the Win key cannot normally be used for shortcuts inside Word for Windows (it really should be available).
This will not give us a perfect result in every case since the previous paragraph could also be a heading, but it will get it right most of the time. It's one of the quirks or tweaks (pick your preferred word) that works around the default behavior without getting too complex. When we find ourselves relying on workarounds, it is usually a nudge to find a better approach.
Not for derived heading styles
The above version doesn’t work for derived heading styles because the regular GoTo methods do not recognize derived heading styles. What's that mean?
For example, in my novels, I derive an Act paragraph style from Heading 1, a Chapter style from Heading 2, and so on, which I use as I write; so this macro would not work in my novels. Most of my novel notes use the standard heading styles Heading 1 – 9, so I could get by with the above macro for those documents. The more general member version will work with derived styles, and we also solve a couple special cases to improve the intuitive behavior.
Improvements?
The macro makes two changes including adding a new paragraph and moving the insertion point. It would be nice to include an undo record, so both changes are undone as a unit. However, be extra careful. If implemented improperly, they can cause significant issues with the Undo-Redo cycle, even to the point of losing some unsaved changes or even confusing cloud-based versions.
This version uses the Selection multiple times, so a better approach would be to use range variable. Also, see the gotchas above for two small issues that this simpler macro does not address.